@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/win32.js CHANGED
@@ -1,573 +1,573 @@
1
- import {
2
- CHAR_DOT,
3
- CHAR_BACKWARD_SLASH,
4
- CHAR_COLON
5
- } from "./constants.js";
6
- import {
7
- assertPath,
8
- isPathSeparator,
9
- isWindowsDeviceRoot,
10
- normalizeString,
11
- _format
12
- } from "./util.js";
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { CHAR_BACKWARD_SLASH, CHAR_COLON, CHAR_DOT } from "./constants.js";
3
+ import { _format, assertPath, isPathSeparator, isWindowsDeviceRoot, normalizeString } from "./util.js";
4
+
5
+ //#region src/win32.ts
6
+ var win32_exports = /* @__PURE__ */ __exportAll({
7
+ basename: () => basename,
8
+ delimiter: () => ";",
9
+ dirname: () => dirname,
10
+ extname: () => extname,
11
+ format: () => format,
12
+ isAbsolute: () => isAbsolute,
13
+ join: () => join,
14
+ normalize: () => normalize,
15
+ parse: () => parse,
16
+ relative: () => relative,
17
+ resolve: () => resolve,
18
+ sep: () => "\\",
19
+ toNamespacedPath: () => toNamespacedPath
20
+ });
13
21
  const sep = "\\";
14
22
  const delimiter = ";";
15
23
  function resolve(...pathSegments) {
16
- let resolvedDevice = "";
17
- let resolvedTail = "";
18
- let resolvedAbsolute = false;
19
- for (let i = pathSegments.length - 1; i >= -1; i--) {
20
- let path;
21
- if (i >= 0) {
22
- path = pathSegments[i];
23
- assertPath(path);
24
- if (path.length === 0) continue;
25
- } else if (resolvedDevice.length === 0) {
26
- path = typeof globalThis.process?.cwd === "function" ? globalThis.process.cwd() : "/";
27
- } else {
28
- path = typeof globalThis.process?.cwd === "function" ? globalThis.process.cwd() : "/";
29
- }
30
- const len = path.length;
31
- let rootEnd = 0;
32
- let device = "";
33
- let isAbsolutePath = false;
34
- const code = path.charCodeAt(0);
35
- if (len > 1) {
36
- if (isPathSeparator(code)) {
37
- isAbsolutePath = true;
38
- if (isPathSeparator(path.charCodeAt(1))) {
39
- let j = 2;
40
- let last = j;
41
- for (; j < len; ++j) {
42
- if (isPathSeparator(path.charCodeAt(j))) break;
43
- }
44
- if (j < len && j !== last) {
45
- const firstPart = path.slice(last, j);
46
- last = j;
47
- for (; j < len; ++j) {
48
- if (!isPathSeparator(path.charCodeAt(j))) break;
49
- }
50
- if (j < len && j !== last) {
51
- last = j;
52
- for (; j < len; ++j) {
53
- if (isPathSeparator(path.charCodeAt(j))) break;
54
- }
55
- if (j === len) {
56
- device = `\\\\${firstPart}\\${path.slice(last)}`;
57
- rootEnd = j;
58
- } else if (j !== last) {
59
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
60
- rootEnd = j;
61
- }
62
- }
63
- }
64
- } else {
65
- rootEnd = 1;
66
- }
67
- } else if (isWindowsDeviceRoot(code)) {
68
- if (path.charCodeAt(1) === CHAR_COLON) {
69
- device = path.slice(0, 2);
70
- rootEnd = 2;
71
- if (len > 2) {
72
- if (isPathSeparator(path.charCodeAt(2))) {
73
- isAbsolutePath = true;
74
- rootEnd = 3;
75
- }
76
- }
77
- }
78
- }
79
- } else if (isPathSeparator(code)) {
80
- rootEnd = 1;
81
- isAbsolutePath = true;
82
- }
83
- if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) {
84
- continue;
85
- }
86
- if (resolvedDevice.length === 0 && device.length > 0) {
87
- resolvedDevice = device;
88
- }
89
- if (!resolvedAbsolute) {
90
- resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
91
- resolvedAbsolute = isAbsolutePath;
92
- }
93
- if (resolvedDevice.length > 0 && resolvedAbsolute) {
94
- break;
95
- }
96
- }
97
- resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator);
98
- return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
24
+ let resolvedDevice = "";
25
+ let resolvedTail = "";
26
+ let resolvedAbsolute = false;
27
+ for (let i = pathSegments.length - 1; i >= -1; i--) {
28
+ let path;
29
+ if (i >= 0) {
30
+ path = pathSegments[i];
31
+ assertPath(path);
32
+ if (path.length === 0) continue;
33
+ } else if (resolvedDevice.length === 0) {
34
+ path = typeof globalThis.process?.cwd === "function" ? globalThis.process.cwd() : "/";
35
+ } else {
36
+ path = typeof globalThis.process?.cwd === "function" ? globalThis.process.cwd() : "/";
37
+ }
38
+ const len = path.length;
39
+ let rootEnd = 0;
40
+ let device = "";
41
+ let isAbsolutePath = false;
42
+ const code = path.charCodeAt(0);
43
+ if (len > 1) {
44
+ if (isPathSeparator(code)) {
45
+ isAbsolutePath = true;
46
+ if (isPathSeparator(path.charCodeAt(1))) {
47
+ let j = 2;
48
+ let last = j;
49
+ for (; j < len; ++j) {
50
+ if (isPathSeparator(path.charCodeAt(j))) break;
51
+ }
52
+ if (j < len && j !== last) {
53
+ const firstPart = path.slice(last, j);
54
+ last = j;
55
+ for (; j < len; ++j) {
56
+ if (!isPathSeparator(path.charCodeAt(j))) break;
57
+ }
58
+ if (j < len && j !== last) {
59
+ last = j;
60
+ for (; j < len; ++j) {
61
+ if (isPathSeparator(path.charCodeAt(j))) break;
62
+ }
63
+ if (j === len) {
64
+ device = `\\\\${firstPart}\\${path.slice(last)}`;
65
+ rootEnd = j;
66
+ } else if (j !== last) {
67
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
68
+ rootEnd = j;
69
+ }
70
+ }
71
+ }
72
+ } else {
73
+ rootEnd = 1;
74
+ }
75
+ } else if (isWindowsDeviceRoot(code)) {
76
+ if (path.charCodeAt(1) === 58) {
77
+ device = path.slice(0, 2);
78
+ rootEnd = 2;
79
+ if (len > 2) {
80
+ if (isPathSeparator(path.charCodeAt(2))) {
81
+ isAbsolutePath = true;
82
+ rootEnd = 3;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ } else if (isPathSeparator(code)) {
88
+ rootEnd = 1;
89
+ isAbsolutePath = true;
90
+ }
91
+ if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) {
92
+ continue;
93
+ }
94
+ if (resolvedDevice.length === 0 && device.length > 0) {
95
+ resolvedDevice = device;
96
+ }
97
+ if (!resolvedAbsolute) {
98
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
99
+ resolvedAbsolute = isAbsolutePath;
100
+ }
101
+ if (resolvedDevice.length > 0 && resolvedAbsolute) {
102
+ break;
103
+ }
104
+ }
105
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator);
106
+ return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
99
107
  }
100
108
  function normalize(path) {
101
- assertPath(path);
102
- const len = path.length;
103
- if (len === 0) return ".";
104
- let rootEnd = 0;
105
- let device;
106
- let isAbsolutePath = false;
107
- const code = path.charCodeAt(0);
108
- if (len > 1) {
109
- if (isPathSeparator(code)) {
110
- isAbsolutePath = true;
111
- if (isPathSeparator(path.charCodeAt(1))) {
112
- let j = 2;
113
- let last = j;
114
- for (; j < len; ++j) {
115
- if (isPathSeparator(path.charCodeAt(j))) break;
116
- }
117
- if (j < len && j !== last) {
118
- const firstPart = path.slice(last, j);
119
- last = j;
120
- for (; j < len; ++j) {
121
- if (!isPathSeparator(path.charCodeAt(j))) break;
122
- }
123
- if (j < len && j !== last) {
124
- last = j;
125
- for (; j < len; ++j) {
126
- if (isPathSeparator(path.charCodeAt(j))) break;
127
- }
128
- if (j === len) {
129
- return `\\\\${firstPart}\\${path.slice(last)}\\`;
130
- } else if (j !== last) {
131
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
132
- rootEnd = j;
133
- }
134
- }
135
- }
136
- } else {
137
- rootEnd = 1;
138
- }
139
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
140
- device = path.slice(0, 2);
141
- rootEnd = 2;
142
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
143
- isAbsolutePath = true;
144
- rootEnd = 3;
145
- }
146
- }
147
- } else if (isPathSeparator(code)) {
148
- return "\\";
149
- }
150
- let tail;
151
- if (rootEnd < len) {
152
- tail = normalizeString(path.slice(rootEnd), !isAbsolutePath, "\\", isPathSeparator);
153
- } else {
154
- tail = "";
155
- }
156
- if (tail.length === 0 && !isAbsolutePath) tail = ".";
157
- if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
158
- tail += "\\";
159
- }
160
- if (device === void 0) {
161
- if (isAbsolutePath) {
162
- if (tail.length > 0) return `\\${tail}`;
163
- return "\\";
164
- }
165
- if (tail.length > 0) return tail;
166
- return "";
167
- }
168
- if (isAbsolutePath) {
169
- if (tail.length > 0) return `${device}\\${tail}`;
170
- return `${device}\\`;
171
- }
172
- if (tail.length > 0) return device + tail;
173
- return device;
109
+ assertPath(path);
110
+ const len = path.length;
111
+ if (len === 0) return ".";
112
+ let rootEnd = 0;
113
+ let device;
114
+ let isAbsolutePath = false;
115
+ const code = path.charCodeAt(0);
116
+ if (len > 1) {
117
+ if (isPathSeparator(code)) {
118
+ isAbsolutePath = true;
119
+ if (isPathSeparator(path.charCodeAt(1))) {
120
+ let j = 2;
121
+ let last = j;
122
+ for (; j < len; ++j) {
123
+ if (isPathSeparator(path.charCodeAt(j))) break;
124
+ }
125
+ if (j < len && j !== last) {
126
+ const firstPart = path.slice(last, j);
127
+ last = j;
128
+ for (; j < len; ++j) {
129
+ if (!isPathSeparator(path.charCodeAt(j))) break;
130
+ }
131
+ if (j < len && j !== last) {
132
+ last = j;
133
+ for (; j < len; ++j) {
134
+ if (isPathSeparator(path.charCodeAt(j))) break;
135
+ }
136
+ if (j === len) {
137
+ return `\\\\${firstPart}\\${path.slice(last)}\\`;
138
+ } else if (j !== last) {
139
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
140
+ rootEnd = j;
141
+ }
142
+ }
143
+ }
144
+ } else {
145
+ rootEnd = 1;
146
+ }
147
+ } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === 58) {
148
+ device = path.slice(0, 2);
149
+ rootEnd = 2;
150
+ if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
151
+ isAbsolutePath = true;
152
+ rootEnd = 3;
153
+ }
154
+ }
155
+ } else if (isPathSeparator(code)) {
156
+ return "\\";
157
+ }
158
+ let tail;
159
+ if (rootEnd < len) {
160
+ tail = normalizeString(path.slice(rootEnd), !isAbsolutePath, "\\", isPathSeparator);
161
+ } else {
162
+ tail = "";
163
+ }
164
+ if (tail.length === 0 && !isAbsolutePath) tail = ".";
165
+ if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
166
+ tail += "\\";
167
+ }
168
+ if (device === undefined) {
169
+ if (isAbsolutePath) {
170
+ if (tail.length > 0) return `\\${tail}`;
171
+ return "\\";
172
+ }
173
+ if (tail.length > 0) return tail;
174
+ return "";
175
+ }
176
+ if (isAbsolutePath) {
177
+ if (tail.length > 0) return `${device}\\${tail}`;
178
+ return `${device}\\`;
179
+ }
180
+ if (tail.length > 0) return device + tail;
181
+ return device;
174
182
  }
175
183
  function isAbsolute(path) {
176
- assertPath(path);
177
- const len = path.length;
178
- if (len === 0) return false;
179
- const code = path.charCodeAt(0);
180
- if (isPathSeparator(code)) return true;
181
- if (isWindowsDeviceRoot(code) && len > 2 && path.charCodeAt(1) === CHAR_COLON) {
182
- if (isPathSeparator(path.charCodeAt(2))) return true;
183
- }
184
- return false;
184
+ assertPath(path);
185
+ const len = path.length;
186
+ if (len === 0) return false;
187
+ const code = path.charCodeAt(0);
188
+ if (isPathSeparator(code)) return true;
189
+ if (isWindowsDeviceRoot(code) && len > 2 && path.charCodeAt(1) === 58) {
190
+ if (isPathSeparator(path.charCodeAt(2))) return true;
191
+ }
192
+ return false;
185
193
  }
186
194
  function join(...paths) {
187
- if (paths.length === 0) return ".";
188
- let joined;
189
- let firstPart;
190
- for (let i = 0; i < paths.length; ++i) {
191
- const arg = paths[i];
192
- assertPath(arg);
193
- if (arg.length > 0) {
194
- if (joined === void 0) {
195
- joined = firstPart = arg;
196
- } else {
197
- joined += `\\${arg}`;
198
- }
199
- }
200
- }
201
- if (joined === void 0) return ".";
202
- let needsReplace = true;
203
- let slashCount = 0;
204
- if (isPathSeparator(firstPart.charCodeAt(0))) {
205
- ++slashCount;
206
- const firstLen = firstPart.length;
207
- if (firstLen > 1) {
208
- if (isPathSeparator(firstPart.charCodeAt(1))) {
209
- ++slashCount;
210
- if (firstLen > 2) {
211
- if (isPathSeparator(firstPart.charCodeAt(2))) ++slashCount;
212
- else needsReplace = false;
213
- }
214
- }
215
- }
216
- }
217
- if (needsReplace) {
218
- for (; slashCount < joined.length; ++slashCount) {
219
- if (!isPathSeparator(joined.charCodeAt(slashCount))) break;
220
- }
221
- if (slashCount >= 2) joined = `\\${joined.slice(slashCount)}`;
222
- }
223
- return normalize(joined);
195
+ if (paths.length === 0) return ".";
196
+ let joined;
197
+ let firstPart;
198
+ for (let i = 0; i < paths.length; ++i) {
199
+ const arg = paths[i];
200
+ assertPath(arg);
201
+ if (arg.length > 0) {
202
+ if (joined === undefined) {
203
+ joined = firstPart = arg;
204
+ } else {
205
+ joined += `\\${arg}`;
206
+ }
207
+ }
208
+ }
209
+ if (joined === undefined) return ".";
210
+ let needsReplace = true;
211
+ let slashCount = 0;
212
+ if (isPathSeparator(firstPart.charCodeAt(0))) {
213
+ ++slashCount;
214
+ const firstLen = firstPart.length;
215
+ if (firstLen > 1) {
216
+ if (isPathSeparator(firstPart.charCodeAt(1))) {
217
+ ++slashCount;
218
+ if (firstLen > 2) {
219
+ if (isPathSeparator(firstPart.charCodeAt(2))) ++slashCount;
220
+ else needsReplace = false;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ if (needsReplace) {
226
+ for (; slashCount < joined.length; ++slashCount) {
227
+ if (!isPathSeparator(joined.charCodeAt(slashCount))) break;
228
+ }
229
+ if (slashCount >= 2) joined = `\\${joined.slice(slashCount)}`;
230
+ }
231
+ return normalize(joined);
224
232
  }
225
233
  function relative(from, to) {
226
- assertPath(from);
227
- assertPath(to);
228
- if (from === to) return "";
229
- const fromOrig = resolve(from);
230
- const toOrig = resolve(to);
231
- if (fromOrig === toOrig) return "";
232
- from = fromOrig.toLowerCase();
233
- to = toOrig.toLowerCase();
234
- if (from === to) return "";
235
- let fromStart = 0;
236
- for (; fromStart < from.length; ++fromStart) {
237
- if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) break;
238
- }
239
- let fromEnd = from.length;
240
- for (; fromEnd - 1 > fromStart; --fromEnd) {
241
- if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) break;
242
- }
243
- const fromLen = fromEnd - fromStart;
244
- let toStart = 0;
245
- for (; toStart < to.length; ++toStart) {
246
- if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) break;
247
- }
248
- let toEnd = to.length;
249
- for (; toEnd - 1 > toStart; --toEnd) {
250
- if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) break;
251
- }
252
- const toLen = toEnd - toStart;
253
- const length = fromLen < toLen ? fromLen : toLen;
254
- let lastCommonSep = -1;
255
- let i = 0;
256
- for (; i <= length; ++i) {
257
- if (i === length) {
258
- if (toLen > length) {
259
- if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
260
- return toOrig.slice(toStart + i + 1);
261
- } else if (i === 2) {
262
- return toOrig.slice(toStart + i);
263
- }
264
- }
265
- if (fromLen > length) {
266
- if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
267
- lastCommonSep = i;
268
- } else if (i === 2) {
269
- lastCommonSep = 3;
270
- }
271
- }
272
- break;
273
- }
274
- const fromCode = from.charCodeAt(fromStart + i);
275
- const toCode = to.charCodeAt(toStart + i);
276
- if (fromCode !== toCode) break;
277
- if (fromCode === CHAR_BACKWARD_SLASH) lastCommonSep = i;
278
- }
279
- if (i !== length && lastCommonSep === -1) {
280
- return toOrig;
281
- }
282
- let out = "";
283
- if (lastCommonSep === -1) lastCommonSep = 0;
284
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
285
- if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
286
- if (out.length === 0) out += "..";
287
- else out += "\\..";
288
- }
289
- }
290
- if (out.length > 0) {
291
- return out + toOrig.slice(toStart + lastCommonSep, toEnd);
292
- }
293
- toStart += lastCommonSep;
294
- if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) ++toStart;
295
- return toOrig.slice(toStart, toEnd);
234
+ assertPath(from);
235
+ assertPath(to);
236
+ if (from === to) return "";
237
+ const fromOrig = resolve(from);
238
+ const toOrig = resolve(to);
239
+ if (fromOrig === toOrig) return "";
240
+ from = fromOrig.toLowerCase();
241
+ to = toOrig.toLowerCase();
242
+ if (from === to) return "";
243
+ let fromStart = 0;
244
+ for (; fromStart < from.length; ++fromStart) {
245
+ if (from.charCodeAt(fromStart) !== 92) break;
246
+ }
247
+ let fromEnd = from.length;
248
+ for (; fromEnd - 1 > fromStart; --fromEnd) {
249
+ if (from.charCodeAt(fromEnd - 1) !== 92) break;
250
+ }
251
+ const fromLen = fromEnd - fromStart;
252
+ let toStart = 0;
253
+ for (; toStart < to.length; ++toStart) {
254
+ if (to.charCodeAt(toStart) !== 92) break;
255
+ }
256
+ let toEnd = to.length;
257
+ for (; toEnd - 1 > toStart; --toEnd) {
258
+ if (to.charCodeAt(toEnd - 1) !== 92) break;
259
+ }
260
+ const toLen = toEnd - toStart;
261
+ const length = fromLen < toLen ? fromLen : toLen;
262
+ let lastCommonSep = -1;
263
+ let i = 0;
264
+ for (; i <= length; ++i) {
265
+ if (i === length) {
266
+ if (toLen > length) {
267
+ if (to.charCodeAt(toStart + i) === 92) {
268
+ return toOrig.slice(toStart + i + 1);
269
+ } else if (i === 2) {
270
+ return toOrig.slice(toStart + i);
271
+ }
272
+ }
273
+ if (fromLen > length) {
274
+ if (from.charCodeAt(fromStart + i) === 92) {
275
+ lastCommonSep = i;
276
+ } else if (i === 2) {
277
+ lastCommonSep = 3;
278
+ }
279
+ }
280
+ break;
281
+ }
282
+ const fromCode = from.charCodeAt(fromStart + i);
283
+ const toCode = to.charCodeAt(toStart + i);
284
+ if (fromCode !== toCode) break;
285
+ if (fromCode === 92) lastCommonSep = i;
286
+ }
287
+ if (i !== length && lastCommonSep === -1) {
288
+ return toOrig;
289
+ }
290
+ let out = "";
291
+ if (lastCommonSep === -1) lastCommonSep = 0;
292
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
293
+ if (i === fromEnd || from.charCodeAt(i) === 92) {
294
+ if (out.length === 0) out += "..";
295
+ else out += "\\..";
296
+ }
297
+ }
298
+ if (out.length > 0) {
299
+ return out + toOrig.slice(toStart + lastCommonSep, toEnd);
300
+ }
301
+ toStart += lastCommonSep;
302
+ if (toOrig.charCodeAt(toStart) === 92) ++toStart;
303
+ return toOrig.slice(toStart, toEnd);
296
304
  }
297
305
  function toNamespacedPath(path) {
298
- if (typeof path !== "string") return path;
299
- if (path.length === 0) return "";
300
- const resolvedPath = resolve(path);
301
- if (resolvedPath.length >= 3) {
302
- if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
303
- if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
304
- const code = resolvedPath.charCodeAt(2);
305
- if (code !== 63 && code !== CHAR_DOT) {
306
- return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
307
- }
308
- }
309
- } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
310
- return `\\\\?\\${resolvedPath}`;
311
- }
312
- }
313
- return path;
306
+ if (typeof path !== "string") return path;
307
+ if (path.length === 0) return "";
308
+ const resolvedPath = resolve(path);
309
+ if (resolvedPath.length >= 3) {
310
+ if (resolvedPath.charCodeAt(0) === 92) {
311
+ if (resolvedPath.charCodeAt(1) === 92) {
312
+ const code = resolvedPath.charCodeAt(2);
313
+ if (code !== 63 && code !== 46) {
314
+ return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
315
+ }
316
+ }
317
+ } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === 58 && resolvedPath.charCodeAt(2) === 92) {
318
+ return `\\\\?\\${resolvedPath}`;
319
+ }
320
+ }
321
+ return path;
314
322
  }
315
323
  function dirname(path) {
316
- assertPath(path);
317
- const len = path.length;
318
- if (len === 0) return ".";
319
- let rootEnd = -1;
320
- let end = -1;
321
- let matchedSlash = true;
322
- let offset = 0;
323
- const code = path.charCodeAt(0);
324
- if (len > 1) {
325
- if (isPathSeparator(code)) {
326
- rootEnd = offset = 1;
327
- if (isPathSeparator(path.charCodeAt(1))) {
328
- let j = 2;
329
- let last = j;
330
- for (; j < len; ++j) {
331
- if (isPathSeparator(path.charCodeAt(j))) break;
332
- }
333
- if (j < len && j !== last) {
334
- last = j;
335
- for (; j < len; ++j) {
336
- if (!isPathSeparator(path.charCodeAt(j))) break;
337
- }
338
- if (j < len && j !== last) {
339
- last = j;
340
- for (; j < len; ++j) {
341
- if (isPathSeparator(path.charCodeAt(j))) break;
342
- }
343
- if (j === len) return path;
344
- if (j !== last) rootEnd = offset = j + 1;
345
- }
346
- }
347
- }
348
- } else if (isWindowsDeviceRoot(code)) {
349
- if (path.charCodeAt(1) === CHAR_COLON) {
350
- rootEnd = offset = 2;
351
- if (len > 2) {
352
- if (isPathSeparator(path.charCodeAt(2))) rootEnd = offset = 3;
353
- }
354
- }
355
- }
356
- } else if (isPathSeparator(code)) {
357
- return path;
358
- }
359
- for (let i = len - 1; i >= offset; --i) {
360
- if (isPathSeparator(path.charCodeAt(i))) {
361
- if (!matchedSlash) {
362
- end = i;
363
- break;
364
- }
365
- } else {
366
- matchedSlash = false;
367
- }
368
- }
369
- if (end === -1) {
370
- if (rootEnd === -1) return ".";
371
- end = rootEnd;
372
- }
373
- return path.slice(0, end);
324
+ assertPath(path);
325
+ const len = path.length;
326
+ if (len === 0) return ".";
327
+ let rootEnd = -1;
328
+ let end = -1;
329
+ let matchedSlash = true;
330
+ let offset = 0;
331
+ const code = path.charCodeAt(0);
332
+ if (len > 1) {
333
+ if (isPathSeparator(code)) {
334
+ rootEnd = offset = 1;
335
+ if (isPathSeparator(path.charCodeAt(1))) {
336
+ let j = 2;
337
+ let last = j;
338
+ for (; j < len; ++j) {
339
+ if (isPathSeparator(path.charCodeAt(j))) break;
340
+ }
341
+ if (j < len && j !== last) {
342
+ last = j;
343
+ for (; j < len; ++j) {
344
+ if (!isPathSeparator(path.charCodeAt(j))) break;
345
+ }
346
+ if (j < len && j !== last) {
347
+ last = j;
348
+ for (; j < len; ++j) {
349
+ if (isPathSeparator(path.charCodeAt(j))) break;
350
+ }
351
+ if (j === len) return path;
352
+ if (j !== last) rootEnd = offset = j + 1;
353
+ }
354
+ }
355
+ }
356
+ } else if (isWindowsDeviceRoot(code)) {
357
+ if (path.charCodeAt(1) === 58) {
358
+ rootEnd = offset = 2;
359
+ if (len > 2) {
360
+ if (isPathSeparator(path.charCodeAt(2))) rootEnd = offset = 3;
361
+ }
362
+ }
363
+ }
364
+ } else if (isPathSeparator(code)) {
365
+ return path;
366
+ }
367
+ for (let i = len - 1; i >= offset; --i) {
368
+ if (isPathSeparator(path.charCodeAt(i))) {
369
+ if (!matchedSlash) {
370
+ end = i;
371
+ break;
372
+ }
373
+ } else {
374
+ matchedSlash = false;
375
+ }
376
+ }
377
+ if (end === -1) {
378
+ if (rootEnd === -1) return ".";
379
+ end = rootEnd;
380
+ }
381
+ return path.slice(0, end);
374
382
  }
375
383
  function basename(path, ext) {
376
- if (ext !== void 0) assertPath(ext);
377
- assertPath(path);
378
- let start = 0;
379
- let end = -1;
380
- let matchedSlash = true;
381
- if (path.length >= 2) {
382
- if (isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) {
383
- start = 2;
384
- }
385
- }
386
- if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
387
- if (ext.length === path.length && ext === path) return "";
388
- let extIdx = ext.length - 1;
389
- let firstNonSlashEnd = -1;
390
- for (let i = path.length - 1; i >= start; --i) {
391
- const code = path.charCodeAt(i);
392
- if (isPathSeparator(code)) {
393
- if (!matchedSlash) {
394
- start = i + 1;
395
- break;
396
- }
397
- } else {
398
- if (firstNonSlashEnd === -1) {
399
- matchedSlash = false;
400
- firstNonSlashEnd = i + 1;
401
- }
402
- if (extIdx >= 0) {
403
- if (code === ext.charCodeAt(extIdx)) {
404
- if (--extIdx === -1) end = i;
405
- } else {
406
- extIdx = -1;
407
- end = firstNonSlashEnd;
408
- }
409
- }
410
- }
411
- }
412
- if (start === end) end = firstNonSlashEnd;
413
- else if (end === -1) end = path.length;
414
- return path.slice(start, end);
415
- } else {
416
- for (let i = path.length - 1; i >= start; --i) {
417
- if (isPathSeparator(path.charCodeAt(i))) {
418
- if (!matchedSlash) {
419
- start = i + 1;
420
- break;
421
- }
422
- } else if (end === -1) {
423
- matchedSlash = false;
424
- end = i + 1;
425
- }
426
- }
427
- if (end === -1) return "";
428
- return path.slice(start, end);
429
- }
384
+ if (ext !== undefined) assertPath(ext);
385
+ assertPath(path);
386
+ let start = 0;
387
+ let end = -1;
388
+ let matchedSlash = true;
389
+ if (path.length >= 2) {
390
+ if (isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === 58) {
391
+ start = 2;
392
+ }
393
+ }
394
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
395
+ if (ext.length === path.length && ext === path) return "";
396
+ let extIdx = ext.length - 1;
397
+ let firstNonSlashEnd = -1;
398
+ for (let i = path.length - 1; i >= start; --i) {
399
+ const code = path.charCodeAt(i);
400
+ if (isPathSeparator(code)) {
401
+ if (!matchedSlash) {
402
+ start = i + 1;
403
+ break;
404
+ }
405
+ } else {
406
+ if (firstNonSlashEnd === -1) {
407
+ matchedSlash = false;
408
+ firstNonSlashEnd = i + 1;
409
+ }
410
+ if (extIdx >= 0) {
411
+ if (code === ext.charCodeAt(extIdx)) {
412
+ if (--extIdx === -1) end = i;
413
+ } else {
414
+ extIdx = -1;
415
+ end = firstNonSlashEnd;
416
+ }
417
+ }
418
+ }
419
+ }
420
+ if (start === end) end = firstNonSlashEnd;
421
+ else if (end === -1) end = path.length;
422
+ return path.slice(start, end);
423
+ } else {
424
+ for (let i = path.length - 1; i >= start; --i) {
425
+ if (isPathSeparator(path.charCodeAt(i))) {
426
+ if (!matchedSlash) {
427
+ start = i + 1;
428
+ break;
429
+ }
430
+ } else if (end === -1) {
431
+ matchedSlash = false;
432
+ end = i + 1;
433
+ }
434
+ }
435
+ if (end === -1) return "";
436
+ return path.slice(start, end);
437
+ }
430
438
  }
431
439
  function extname(path) {
432
- assertPath(path);
433
- let start = 0;
434
- let startDot = -1;
435
- let startPart = 0;
436
- let end = -1;
437
- let matchedSlash = true;
438
- let preDotState = 0;
439
- if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) {
440
- start = startPart = 2;
441
- }
442
- for (let i = path.length - 1; i >= start; --i) {
443
- const code = path.charCodeAt(i);
444
- if (isPathSeparator(code)) {
445
- if (!matchedSlash) {
446
- startPart = i + 1;
447
- break;
448
- }
449
- continue;
450
- }
451
- if (end === -1) {
452
- matchedSlash = false;
453
- end = i + 1;
454
- }
455
- if (code === CHAR_DOT) {
456
- if (startDot === -1) startDot = i;
457
- else if (preDotState !== 1) preDotState = 1;
458
- } else if (startDot !== -1) {
459
- preDotState = -1;
460
- }
461
- }
462
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
463
- return "";
464
- }
465
- return path.slice(startDot, end);
440
+ assertPath(path);
441
+ let start = 0;
442
+ let startDot = -1;
443
+ let startPart = 0;
444
+ let end = -1;
445
+ let matchedSlash = true;
446
+ let preDotState = 0;
447
+ if (path.length >= 2 && path.charCodeAt(1) === 58 && isWindowsDeviceRoot(path.charCodeAt(0))) {
448
+ start = startPart = 2;
449
+ }
450
+ for (let i = path.length - 1; i >= start; --i) {
451
+ const code = path.charCodeAt(i);
452
+ if (isPathSeparator(code)) {
453
+ if (!matchedSlash) {
454
+ startPart = i + 1;
455
+ break;
456
+ }
457
+ continue;
458
+ }
459
+ if (end === -1) {
460
+ matchedSlash = false;
461
+ end = i + 1;
462
+ }
463
+ if (code === 46) {
464
+ if (startDot === -1) startDot = i;
465
+ else if (preDotState !== 1) preDotState = 1;
466
+ } else if (startDot !== -1) {
467
+ preDotState = -1;
468
+ }
469
+ }
470
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
471
+ return "";
472
+ }
473
+ return path.slice(startDot, end);
466
474
  }
467
475
  function format(pathObject) {
468
- if (pathObject === null || typeof pathObject !== "object") {
469
- throw new TypeError(
470
- 'The "pathObject" argument must be of type Object. Received type ' + typeof pathObject
471
- );
472
- }
473
- return _format("\\", pathObject);
476
+ if (pathObject === null || typeof pathObject !== "object") {
477
+ throw new TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof pathObject);
478
+ }
479
+ return _format("\\", pathObject);
474
480
  }
475
481
  function parse(path) {
476
- assertPath(path);
477
- const ret = { root: "", dir: "", base: "", ext: "", name: "" };
478
- if (path.length === 0) return ret;
479
- const len = path.length;
480
- let rootEnd = 0;
481
- let code = path.charCodeAt(0);
482
- if (len > 1) {
483
- if (isPathSeparator(code)) {
484
- rootEnd = 1;
485
- if (isPathSeparator(path.charCodeAt(1))) {
486
- let j = 2;
487
- let last = j;
488
- for (; j < len; ++j) {
489
- if (isPathSeparator(path.charCodeAt(j))) break;
490
- }
491
- if (j < len && j !== last) {
492
- last = j;
493
- for (; j < len; ++j) {
494
- if (!isPathSeparator(path.charCodeAt(j))) break;
495
- }
496
- if (j < len && j !== last) {
497
- last = j;
498
- for (; j < len; ++j) {
499
- if (isPathSeparator(path.charCodeAt(j))) break;
500
- }
501
- if (j === len) rootEnd = j;
502
- else if (j !== last) rootEnd = j + 1;
503
- }
504
- }
505
- }
506
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
507
- rootEnd = 2;
508
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
509
- rootEnd = 3;
510
- }
511
- }
512
- } else if (isPathSeparator(code)) {
513
- ret.root = ret.dir = path;
514
- return ret;
515
- }
516
- if (rootEnd > 0) ret.root = path.slice(0, rootEnd);
517
- let startDot = -1;
518
- let startPart = rootEnd;
519
- let end = -1;
520
- let matchedSlash = true;
521
- let i = path.length - 1;
522
- let preDotState = 0;
523
- for (; i >= rootEnd; --i) {
524
- code = path.charCodeAt(i);
525
- if (isPathSeparator(code)) {
526
- if (!matchedSlash) {
527
- startPart = i + 1;
528
- break;
529
- }
530
- continue;
531
- }
532
- if (end === -1) {
533
- matchedSlash = false;
534
- end = i + 1;
535
- }
536
- if (code === CHAR_DOT) {
537
- if (startDot === -1) startDot = i;
538
- else if (preDotState !== 1) preDotState = 1;
539
- } else if (startDot !== -1) {
540
- preDotState = -1;
541
- }
542
- }
543
- if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
544
- if (end !== -1) {
545
- ret.base = ret.name = path.slice(startPart, end);
546
- }
547
- } else {
548
- ret.name = path.slice(startPart, startDot);
549
- ret.base = path.slice(startPart, end);
550
- ret.ext = path.slice(startDot, end);
551
- }
552
- if (startPart > 0 && startPart !== rootEnd) {
553
- ret.dir = path.slice(0, startPart - 1);
554
- } else {
555
- ret.dir = ret.root;
556
- }
557
- return ret;
482
+ assertPath(path);
483
+ const ret = {
484
+ root: "",
485
+ dir: "",
486
+ base: "",
487
+ ext: "",
488
+ name: ""
489
+ };
490
+ if (path.length === 0) return ret;
491
+ const len = path.length;
492
+ let rootEnd = 0;
493
+ let code = path.charCodeAt(0);
494
+ if (len > 1) {
495
+ if (isPathSeparator(code)) {
496
+ rootEnd = 1;
497
+ if (isPathSeparator(path.charCodeAt(1))) {
498
+ let j = 2;
499
+ let last = j;
500
+ for (; j < len; ++j) {
501
+ if (isPathSeparator(path.charCodeAt(j))) break;
502
+ }
503
+ if (j < len && j !== last) {
504
+ last = j;
505
+ for (; j < len; ++j) {
506
+ if (!isPathSeparator(path.charCodeAt(j))) break;
507
+ }
508
+ if (j < len && j !== last) {
509
+ last = j;
510
+ for (; j < len; ++j) {
511
+ if (isPathSeparator(path.charCodeAt(j))) break;
512
+ }
513
+ if (j === len) rootEnd = j;
514
+ else if (j !== last) rootEnd = j + 1;
515
+ }
516
+ }
517
+ }
518
+ } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === 58) {
519
+ rootEnd = 2;
520
+ if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
521
+ rootEnd = 3;
522
+ }
523
+ }
524
+ } else if (isPathSeparator(code)) {
525
+ ret.root = ret.dir = path;
526
+ return ret;
527
+ }
528
+ if (rootEnd > 0) ret.root = path.slice(0, rootEnd);
529
+ let startDot = -1;
530
+ let startPart = rootEnd;
531
+ let end = -1;
532
+ let matchedSlash = true;
533
+ let i = path.length - 1;
534
+ let preDotState = 0;
535
+ for (; i >= rootEnd; --i) {
536
+ code = path.charCodeAt(i);
537
+ if (isPathSeparator(code)) {
538
+ if (!matchedSlash) {
539
+ startPart = i + 1;
540
+ break;
541
+ }
542
+ continue;
543
+ }
544
+ if (end === -1) {
545
+ matchedSlash = false;
546
+ end = i + 1;
547
+ }
548
+ if (code === 46) {
549
+ if (startDot === -1) startDot = i;
550
+ else if (preDotState !== 1) preDotState = 1;
551
+ } else if (startDot !== -1) {
552
+ preDotState = -1;
553
+ }
554
+ }
555
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
556
+ if (end !== -1) {
557
+ ret.base = ret.name = path.slice(startPart, end);
558
+ }
559
+ } else {
560
+ ret.name = path.slice(startPart, startDot);
561
+ ret.base = path.slice(startPart, end);
562
+ ret.ext = path.slice(startDot, end);
563
+ }
564
+ if (startPart > 0 && startPart !== rootEnd) {
565
+ ret.dir = path.slice(0, startPart - 1);
566
+ } else {
567
+ ret.dir = ret.root;
568
+ }
569
+ return ret;
558
570
  }
559
- export {
560
- basename,
561
- delimiter,
562
- dirname,
563
- extname,
564
- format,
565
- isAbsolute,
566
- join,
567
- normalize,
568
- parse,
569
- relative,
570
- resolve,
571
- sep,
572
- toNamespacedPath
573
- };
571
+
572
+ //#endregion
573
+ export { basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve, sep, toNamespacedPath, win32_exports };