@gjsify/path 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/constants.js +4 -11
- package/lib/esm/index.js +24 -51
- package/lib/esm/posix.js +316 -312
- package/lib/esm/util.js +92 -99
- package/lib/esm/win32.js +549 -549
- package/package.json +3 -3
package/lib/esm/util.js
CHANGED
|
@@ -1,113 +1,106 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
CHAR_BACKWARD_SLASH
|
|
5
|
-
} from "./constants.js";
|
|
1
|
+
import { CHAR_BACKWARD_SLASH, CHAR_DOT, CHAR_FORWARD_SLASH } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/util.ts
|
|
6
4
|
function assertPath(path) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
);
|
|
11
|
-
}
|
|
5
|
+
if (typeof path !== "string") {
|
|
6
|
+
throw new TypeError("The \"path\" argument must be of type string. Received type " + typeof path);
|
|
7
|
+
}
|
|
12
8
|
}
|
|
13
9
|
function isPosixPathSeparator(code) {
|
|
14
|
-
|
|
10
|
+
return code === 47;
|
|
15
11
|
}
|
|
16
12
|
function isPathSeparator(code) {
|
|
17
|
-
|
|
13
|
+
return code === 47 || code === 92;
|
|
18
14
|
}
|
|
19
15
|
function isWindowsDeviceRoot(code) {
|
|
20
|
-
|
|
21
|
-
code >= 97 && code <= 122;
|
|
16
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
22
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves `.` and `..` segments in a path string.
|
|
20
|
+
*/
|
|
23
21
|
function normalizeString(path, allowAboveRoot, separator, isPathSep) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return res;
|
|
22
|
+
let res = "";
|
|
23
|
+
let lastSegmentLength = 0;
|
|
24
|
+
let lastSlash = -1;
|
|
25
|
+
let dots = 0;
|
|
26
|
+
let code;
|
|
27
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
28
|
+
if (i < path.length) {
|
|
29
|
+
code = path.charCodeAt(i);
|
|
30
|
+
} else if (isPathSep(code)) {
|
|
31
|
+
break;
|
|
32
|
+
} else {
|
|
33
|
+
code = 47;
|
|
34
|
+
}
|
|
35
|
+
if (isPathSep(code)) {
|
|
36
|
+
if (lastSlash === i - 1 || dots === 1) {} else if (lastSlash !== i - 1 && dots === 2) {
|
|
37
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
38
|
+
if (res.length > 2) {
|
|
39
|
+
const lastSlashIndex = res.lastIndexOf(separator);
|
|
40
|
+
if (lastSlashIndex === -1) {
|
|
41
|
+
res = "";
|
|
42
|
+
lastSegmentLength = 0;
|
|
43
|
+
} else {
|
|
44
|
+
res = res.slice(0, lastSlashIndex);
|
|
45
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
|
|
46
|
+
}
|
|
47
|
+
lastSlash = i;
|
|
48
|
+
dots = 0;
|
|
49
|
+
continue;
|
|
50
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
51
|
+
res = "";
|
|
52
|
+
lastSegmentLength = 0;
|
|
53
|
+
lastSlash = i;
|
|
54
|
+
dots = 0;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (allowAboveRoot) {
|
|
59
|
+
if (res.length > 0) {
|
|
60
|
+
res += `${separator}..`;
|
|
61
|
+
} else {
|
|
62
|
+
res = "..";
|
|
63
|
+
}
|
|
64
|
+
lastSegmentLength = 2;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
if (res.length > 0) {
|
|
68
|
+
res += separator + path.slice(lastSlash + 1, i);
|
|
69
|
+
} else {
|
|
70
|
+
res = path.slice(lastSlash + 1, i);
|
|
71
|
+
}
|
|
72
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
73
|
+
}
|
|
74
|
+
lastSlash = i;
|
|
75
|
+
dots = 0;
|
|
76
|
+
} else if (code === 46 && dots !== -1) {
|
|
77
|
+
++dots;
|
|
78
|
+
} else {
|
|
79
|
+
dots = -1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return res;
|
|
86
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Format a parsed path object into a path string.
|
|
86
|
+
*/
|
|
87
87
|
function _format(sep, pathObject) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
return dir + sep + base;
|
|
88
|
+
if (pathObject === null || typeof pathObject !== "object") {
|
|
89
|
+
throw new TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof pathObject);
|
|
90
|
+
}
|
|
91
|
+
const dir = pathObject.dir || pathObject.root;
|
|
92
|
+
const base = pathObject.base || (pathObject.name || "") + formatExt(pathObject.ext);
|
|
93
|
+
if (!dir) {
|
|
94
|
+
return base;
|
|
95
|
+
}
|
|
96
|
+
if (dir === pathObject.root) {
|
|
97
|
+
return dir + base;
|
|
98
|
+
}
|
|
99
|
+
return dir + sep + base;
|
|
102
100
|
}
|
|
103
101
|
function formatExt(ext) {
|
|
104
|
-
|
|
102
|
+
return ext ? `${ext[0] === "." ? "" : "."}${ext}` : "";
|
|
105
103
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
isPathSeparator,
|
|
110
|
-
isPosixPathSeparator,
|
|
111
|
-
isWindowsDeviceRoot,
|
|
112
|
-
normalizeString
|
|
113
|
-
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { _format, assertPath, isPathSeparator, isPosixPathSeparator, isWindowsDeviceRoot, normalizeString };
|