source: trip-planner-front/node_modules/upath/build/code/upath.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/**
2* upath http://github.com/anodynos/upath/
3*
4* A proxy to `path`, replacing `\` with `/` for all results & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.
5* Version 1.2.0 - Compiled on 2019-09-02 23:33:57
6* Repository git://github.com/anodynos/upath
7* Copyright(c) 2019 Angelos Pikoulas <agelos.pikoulas@gmail.com>
8* License MIT
9*/
10
11// Generated by uRequire v0.7.0-beta.33 target: 'lib' template: 'nodejs'
12
13
14var VERSION = '1.2.0'; // injected by urequire-rc-inject-version
15
16var extraFn, extraFunctions, isFunction, isString, isValidExt, name, path, propName, propValue, toUnix, upath, slice = [].slice, indexOf = [].indexOf || function (item) {
17 for (var i = 0, l = this.length; i < l; i++) {
18 if (i in this && this[i] === item)
19 return i;
20 }
21 return -1;
22 }, hasProp = {}.hasOwnProperty;
23path = require("path");
24isFunction = function (val) {
25 return val instanceof Function;
26};
27isString = function (val) {
28 return typeof val === "string" || !!val && typeof val === "object" && Object.prototype.toString.call(val) === "[object String]";
29};
30upath = exports;
31upath.VERSION = typeof VERSION !== "undefined" && VERSION !== null ? VERSION : "NO-VERSION";
32toUnix = function (p) {
33 var double;
34 p = p.replace(/\\/g, "/");
35 double = /\/\//;
36 while (p.match(double)) {
37 p = p.replace(double, "/");
38 }
39 return p;
40};
41for (propName in path) {
42 propValue = path[propName];
43 if (isFunction(propValue)) {
44 upath[propName] = function (propName) {
45 return function () {
46 var args, result;
47 args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
48 args = args.map(function (p) {
49 if (isString(p)) {
50 return toUnix(p);
51 } else {
52 return p;
53 }
54 });
55 result = path[propName].apply(path, args);
56 if (isString(result)) {
57 return toUnix(result);
58 } else {
59 return result;
60 }
61 };
62 }(propName);
63 } else {
64 upath[propName] = propValue;
65 }
66}
67upath.sep = "/";
68extraFunctions = {
69 toUnix: toUnix,
70 normalizeSafe: function (p) {
71 p = toUnix(p);
72 if (p.startsWith("./")) {
73 if (p.startsWith("./..") || p === "./") {
74 return upath.normalize(p);
75 } else {
76 return "./" + upath.normalize(p);
77 }
78 } else {
79 return upath.normalize(p);
80 }
81 },
82 normalizeTrim: function (p) {
83 p = upath.normalizeSafe(p);
84 if (p.endsWith("/")) {
85 return p.slice(0, +(p.length - 2) + 1 || 9000000000);
86 } else {
87 return p;
88 }
89 },
90 joinSafe: function () {
91 var p, result;
92 p = 1 <= arguments.length ? slice.call(arguments, 0) : [];
93 result = upath.join.apply(null, p);
94 if (p[0].startsWith("./") && !result.startsWith("./")) {
95 result = "./" + result;
96 }
97 return result;
98 },
99 addExt: function (file, ext) {
100 if (!ext) {
101 return file;
102 } else {
103 if (ext[0] !== ".") {
104 ext = "." + ext;
105 }
106 return file + (file.endsWith(ext) ? "" : ext);
107 }
108 },
109 trimExt: function (filename, ignoreExts, maxSize) {
110 var oldExt;
111 if (maxSize == null) {
112 maxSize = 7;
113 }
114 oldExt = upath.extname(filename);
115 if (isValidExt(oldExt, ignoreExts, maxSize)) {
116 return filename.slice(0, +(filename.length - oldExt.length - 1) + 1 || 9000000000);
117 } else {
118 return filename;
119 }
120 },
121 removeExt: function (filename, ext) {
122 if (!ext) {
123 return filename;
124 } else {
125 ext = ext[0] === "." ? ext : "." + ext;
126 if (upath.extname(filename) === ext) {
127 return upath.trimExt(filename);
128 } else {
129 return filename;
130 }
131 }
132 },
133 changeExt: function (filename, ext, ignoreExts, maxSize) {
134 if (maxSize == null) {
135 maxSize = 7;
136 }
137 return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? "" : ext[0] === "." ? ext : "." + ext);
138 },
139 defaultExt: function (filename, ext, ignoreExts, maxSize) {
140 var oldExt;
141 if (maxSize == null) {
142 maxSize = 7;
143 }
144 oldExt = upath.extname(filename);
145 if (isValidExt(oldExt, ignoreExts, maxSize)) {
146 return filename;
147 } else {
148 return upath.addExt(filename, ext);
149 }
150 }
151};
152isValidExt = function (ext, ignoreExts, maxSize) {
153 if (ignoreExts == null) {
154 ignoreExts = [];
155 }
156 return ext && ext.length <= maxSize && indexOf.call(ignoreExts.map(function (e) {
157 return (e && e[0] !== "." ? "." : "") + e;
158 }), ext) < 0;
159};
160for (name in extraFunctions) {
161 if (!hasProp.call(extraFunctions, name))
162 continue;
163 extraFn = extraFunctions[name];
164 if (upath[name] !== void 0) {
165 throw new Error("path." + name + " already exists.");
166 } else {
167 upath[name] = extraFn;
168 }
169}
170
171;
Note: See TracBrowser for help on using the repository browser.