UNPKG

2.54 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.normalizePathEnding = exports.normalize = exports.join = exports.getPathSep = exports.dirname = void 0;
13 function dirname(path) {
14 var sep = getPathSep(path);
15 var parts = normalize(path).split('/');
16 parts.pop();
17 if (parts.length === 1 && parts[0] === '') {
18 return sep;
19 }
20 return parts.join(sep);
21 }
22 exports.dirname = dirname;
23 function getPathSep() {
24 var paths = [];
25 for (var _i = 0; _i < arguments.length; _i++) {
26 paths[_i] = arguments[_i];
27 }
28 return paths.some(function (path) { return /\\/.test(path); }) ? '\\' : '/';
29 }
30 exports.getPathSep = getPathSep;
31 function join() {
32 var paths = [];
33 for (var _i = 0; _i < arguments.length; _i++) {
34 paths[_i] = arguments[_i];
35 }
36 var sep = getPathSep.apply(void 0, paths);
37 var normalPaths = paths.map(normalize);
38 var basePathParts = normalPaths[0].split('/');
39 if (basePathParts.length > 1 &&
40 basePathParts[basePathParts.length - 1] === '') {
41 basePathParts.pop();
42 }
43 for (var _a = 0, _b = normalPaths.slice(1); _a < _b.length; _a++) {
44 var path = _b[_a];
45 for (var _c = 0, _d = path.split('/'); _c < _d.length; _c++) {
46 var part = _d[_c];
47 if (part === '..') {
48 basePathParts.pop();
49 }
50 else if (part !== '.') {
51 basePathParts.push(part);
52 }
53 }
54 }
55 return basePathParts.join(sep);
56 }
57 exports.join = join;
58 function normalize(path) {
59 return path.replace(/\\/g, '/');
60 }
61 exports.normalize = normalize;
62 function normalizePathEnding(path, pathSep) {
63 if (pathSep === void 0) { pathSep = '/'; }
64 if (path && path.length > 0 && path[path.length - 1] !== pathSep) {
65 return "" + path + pathSep;
66 }
67 return path;
68 }
69 exports.normalizePathEnding = normalizePathEnding;
70});
71//# sourceMappingURL=path.js.map
\No newline at end of file