keep-a-changelog 0.10.3 → 2.0.1

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +13 -185
  2. package/LICENSE +1 -1
  3. package/README.md +93 -63
  4. package/esm/_dnt.shims.js +62 -0
  5. package/esm/bin.js +114 -0
  6. package/esm/deps/deno_land/std_0.120.0/_util/assert.js +13 -0
  7. package/esm/deps/deno_land/std_0.120.0/_util/os.js +15 -0
  8. package/esm/deps/deno_land/std_0.120.0/flags/mod.js +255 -0
  9. package/esm/deps/deno_land/std_0.120.0/path/_constants.js +45 -0
  10. package/esm/deps/deno_land/std_0.120.0/path/_interface.js +3 -0
  11. package/esm/deps/deno_land/std_0.120.0/path/_util.js +114 -0
  12. package/esm/deps/deno_land/std_0.120.0/path/common.js +36 -0
  13. package/esm/deps/deno_land/std_0.120.0/path/glob.js +361 -0
  14. package/esm/deps/deno_land/std_0.120.0/path/mod.js +14 -0
  15. package/esm/deps/deno_land/std_0.120.0/path/posix.js +493 -0
  16. package/esm/deps/deno_land/std_0.120.0/path/separator.js +5 -0
  17. package/esm/deps/deno_land/std_0.120.0/path/win32.js +963 -0
  18. package/esm/deps/deno_land/std_0.51.0/fs/eol.js +29 -0
  19. package/esm/deps/deno_land/x/ini_v2.1.0/ini.js +226 -0
  20. package/esm/deps/deno_land/x/ini_v2.1.0/mod.js +1 -0
  21. package/esm/deps/deno_land/x/semver_v1.4.0/mod.js +1527 -0
  22. package/esm/mod.js +5 -0
  23. package/esm/package.json +3 -0
  24. package/esm/src/Change.js +48 -0
  25. package/esm/src/Changelog.js +137 -0
  26. package/esm/src/Release.js +204 -0
  27. package/esm/src/deps.js +1 -0
  28. package/esm/src/parser.js +159 -0
  29. package/esm/test/changelog.custom.type.md +24 -0
  30. package/esm/test/changelog.expected.md +169 -0
  31. package/esm/test/changelog.md +200 -0
  32. package/esm/test/empty.expected.md +6 -0
  33. package/package.json +26 -24
  34. package/types/_dnt.shims.d.ts +9 -0
  35. package/types/bin.d.ts +2 -0
  36. package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +5 -0
  37. package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +3 -0
  38. package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +50 -0
  39. package/types/deps/deno_land/std_0.120.0/path/_constants.d.ts +39 -0
  40. package/types/deps/deno_land/std_0.120.0/path/_interface.d.ts +26 -0
  41. package/types/deps/deno_land/std_0.120.0/path/_util.d.ts +8 -0
  42. package/types/deps/deno_land/std_0.120.0/path/common.d.ts +13 -0
  43. package/types/deps/deno_land/std_0.120.0/path/glob.d.ts +78 -0
  44. package/types/deps/deno_land/std_0.120.0/path/mod.d.ts +9 -0
  45. package/types/deps/deno_land/std_0.120.0/path/posix.d.ts +80 -0
  46. package/types/deps/deno_land/std_0.120.0/path/separator.d.ts +2 -0
  47. package/types/deps/deno_land/std_0.120.0/path/win32.d.ts +87 -0
  48. package/types/deps/deno_land/std_0.51.0/fs/eol.d.ts +12 -0
  49. package/types/deps/deno_land/x/ini_v2.1.0/ini.d.ts +53 -0
  50. package/types/deps/deno_land/x/ini_v2.1.0/mod.d.ts +1 -0
  51. package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +116 -0
  52. package/types/mod.d.ts +5 -0
  53. package/types/src/Change.d.ts +8 -0
  54. package/types/src/Changelog.d.ts +18 -0
  55. package/types/src/Release.d.ts +25 -0
  56. package/types/src/deps.d.ts +1 -0
  57. package/types/src/parser.d.ts +11 -0
  58. package/umd/_dnt.shims.js +76 -0
  59. package/umd/bin.js +145 -0
  60. package/umd/deps/deno_land/std_0.120.0/_util/assert.js +28 -0
  61. package/umd/deps/deno_land/std_0.120.0/_util/os.js +47 -0
  62. package/umd/deps/deno_land/std_0.120.0/flags/mod.js +269 -0
  63. package/umd/deps/deno_land/std_0.120.0/path/_constants.js +58 -0
  64. package/umd/deps/deno_land/std_0.120.0/path/_interface.js +14 -0
  65. package/umd/deps/deno_land/std_0.120.0/path/_util.js +134 -0
  66. package/umd/deps/deno_land/std_0.120.0/path/common.js +50 -0
  67. package/umd/deps/deno_land/std_0.120.0/path/glob.js +397 -0
  68. package/umd/deps/deno_land/std_0.120.0/path/mod.js +51 -0
  69. package/umd/deps/deno_land/std_0.120.0/path/posix.js +538 -0
  70. package/umd/deps/deno_land/std_0.120.0/path/separator.js +18 -0
  71. package/umd/deps/deno_land/std_0.120.0/path/win32.js +1008 -0
  72. package/umd/deps/deno_land/std_0.51.0/fs/eol.js +44 -0
  73. package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +262 -0
  74. package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +23 -0
  75. package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +1578 -0
  76. package/umd/mod.js +24 -0
  77. package/umd/package.json +3 -0
  78. package/umd/src/Change.js +61 -0
  79. package/umd/src/Changelog.js +150 -0
  80. package/umd/src/Release.js +220 -0
  81. package/umd/src/deps.js +19 -0
  82. package/umd/src/parser.js +175 -0
  83. package/umd/test/changelog.custom.type.md +24 -0
  84. package/umd/test/changelog.expected.md +169 -0
  85. package/umd/test/changelog.md +200 -0
  86. package/umd/test/empty.expected.md +6 -0
  87. package/bin.js +0 -114
  88. package/src/Change.js +0 -40
  89. package/src/Changelog.js +0 -121
  90. package/src/Release.js +0 -220
  91. package/src/index.js +0 -6
  92. package/src/parser.js +0 -182
@@ -0,0 +1,1008 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ }) : (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ o[k2] = m[k];
7
+ }));
8
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
9
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
10
+ }) : function(o, v) {
11
+ o["default"] = v;
12
+ });
13
+ var __importStar = (this && this.__importStar) || function (mod) {
14
+ if (mod && mod.__esModule) return mod;
15
+ var result = {};
16
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ __setModuleDefault(result, mod);
18
+ return result;
19
+ };
20
+ (function (factory) {
21
+ if (typeof module === "object" && typeof module.exports === "object") {
22
+ var v = factory(require, exports);
23
+ if (v !== undefined) module.exports = v;
24
+ }
25
+ else if (typeof define === "function" && define.amd) {
26
+ define(["require", "exports", "../../../../_dnt.shims.js", "./_constants.js", "./_util.js", "../_util/assert.js"], factory);
27
+ }
28
+ })(function (require, exports) {
29
+ "use strict";
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.toFileUrl = exports.fromFileUrl = exports.parse = exports.format = exports.extname = exports.basename = exports.dirname = exports.toNamespacedPath = exports.relative = exports.join = exports.isAbsolute = exports.normalize = exports.resolve = exports.delimiter = exports.sep = void 0;
32
+ const dntShim = __importStar(require("../../../../_dnt.shims.js"));
33
+ const _constants_js_1 = require("./_constants.js");
34
+ const _util_js_1 = require("./_util.js");
35
+ const assert_js_1 = require("../_util/assert.js");
36
+ exports.sep = "\\";
37
+ exports.delimiter = ";";
38
+ /**
39
+ * Resolves path segments into a `path`
40
+ * @param pathSegments to process to path
41
+ */
42
+ function resolve(...pathSegments) {
43
+ let resolvedDevice = "";
44
+ let resolvedTail = "";
45
+ let resolvedAbsolute = false;
46
+ for (let i = pathSegments.length - 1; i >= -1; i--) {
47
+ let path;
48
+ // deno-lint-ignore no-explicit-any
49
+ const { Deno } = dntShim.dntGlobalThis;
50
+ if (i >= 0) {
51
+ path = pathSegments[i];
52
+ }
53
+ else if (!resolvedDevice) {
54
+ if (typeof Deno?.cwd !== "function") {
55
+ throw new TypeError("Resolved a drive-letter-less path without a CWD.");
56
+ }
57
+ path = Deno.cwd();
58
+ }
59
+ else {
60
+ if (typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function") {
61
+ throw new TypeError("Resolved a relative path without a CWD.");
62
+ }
63
+ path = Deno.cwd();
64
+ // Verify that a cwd was found and that it actually points
65
+ // to our drive. If not, default to the drive's root.
66
+ if (path === undefined ||
67
+ path.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) {
68
+ path = `${resolvedDevice}\\`;
69
+ }
70
+ }
71
+ (0, _util_js_1.assertPath)(path);
72
+ const len = path.length;
73
+ // Skip empty entries
74
+ if (len === 0)
75
+ continue;
76
+ let rootEnd = 0;
77
+ let device = "";
78
+ let isAbsolute = false;
79
+ const code = path.charCodeAt(0);
80
+ // Try to match a root
81
+ if (len > 1) {
82
+ if ((0, _util_js_1.isPathSeparator)(code)) {
83
+ // Possible UNC root
84
+ // If we started with a separator, we know we at least have an
85
+ // absolute path of some kind (UNC or otherwise)
86
+ isAbsolute = true;
87
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
88
+ // Matched double path separator at beginning
89
+ let j = 2;
90
+ let last = j;
91
+ // Match 1 or more non-path separators
92
+ for (; j < len; ++j) {
93
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
94
+ break;
95
+ }
96
+ if (j < len && j !== last) {
97
+ const firstPart = path.slice(last, j);
98
+ // Matched!
99
+ last = j;
100
+ // Match 1 or more path separators
101
+ for (; j < len; ++j) {
102
+ if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
103
+ break;
104
+ }
105
+ if (j < len && j !== last) {
106
+ // Matched!
107
+ last = j;
108
+ // Match 1 or more non-path separators
109
+ for (; j < len; ++j) {
110
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
111
+ break;
112
+ }
113
+ if (j === len) {
114
+ // We matched a UNC root only
115
+ device = `\\\\${firstPart}\\${path.slice(last)}`;
116
+ rootEnd = j;
117
+ }
118
+ else if (j !== last) {
119
+ // We matched a UNC root with leftovers
120
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
121
+ rootEnd = j;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ else {
127
+ rootEnd = 1;
128
+ }
129
+ }
130
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
131
+ // Possible device root
132
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
133
+ device = path.slice(0, 2);
134
+ rootEnd = 2;
135
+ if (len > 2) {
136
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
137
+ // Treat separator following drive name as an absolute path
138
+ // indicator
139
+ isAbsolute = true;
140
+ rootEnd = 3;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ else if ((0, _util_js_1.isPathSeparator)(code)) {
147
+ // `path` contains just a path separator
148
+ rootEnd = 1;
149
+ isAbsolute = true;
150
+ }
151
+ if (device.length > 0 &&
152
+ resolvedDevice.length > 0 &&
153
+ device.toLowerCase() !== resolvedDevice.toLowerCase()) {
154
+ // This path points to another device so it is not applicable
155
+ continue;
156
+ }
157
+ if (resolvedDevice.length === 0 && device.length > 0) {
158
+ resolvedDevice = device;
159
+ }
160
+ if (!resolvedAbsolute) {
161
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
162
+ resolvedAbsolute = isAbsolute;
163
+ }
164
+ if (resolvedAbsolute && resolvedDevice.length > 0)
165
+ break;
166
+ }
167
+ // At this point the path should be resolved to a full absolute path,
168
+ // but handle relative paths to be safe (might happen when process.cwd()
169
+ // fails)
170
+ // Normalize the tail path
171
+ resolvedTail = (0, _util_js_1.normalizeString)(resolvedTail, !resolvedAbsolute, "\\", _util_js_1.isPathSeparator);
172
+ return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
173
+ }
174
+ exports.resolve = resolve;
175
+ /**
176
+ * Normalizes a `path`
177
+ * @param path to normalize
178
+ */
179
+ function normalize(path) {
180
+ (0, _util_js_1.assertPath)(path);
181
+ const len = path.length;
182
+ if (len === 0)
183
+ return ".";
184
+ let rootEnd = 0;
185
+ let device;
186
+ let isAbsolute = false;
187
+ const code = path.charCodeAt(0);
188
+ // Try to match a root
189
+ if (len > 1) {
190
+ if ((0, _util_js_1.isPathSeparator)(code)) {
191
+ // Possible UNC root
192
+ // If we started with a separator, we know we at least have an absolute
193
+ // path of some kind (UNC or otherwise)
194
+ isAbsolute = true;
195
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
196
+ // Matched double path separator at beginning
197
+ let j = 2;
198
+ let last = j;
199
+ // Match 1 or more non-path separators
200
+ for (; j < len; ++j) {
201
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
202
+ break;
203
+ }
204
+ if (j < len && j !== last) {
205
+ const firstPart = path.slice(last, j);
206
+ // Matched!
207
+ last = j;
208
+ // Match 1 or more path separators
209
+ for (; j < len; ++j) {
210
+ if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
211
+ break;
212
+ }
213
+ if (j < len && j !== last) {
214
+ // Matched!
215
+ last = j;
216
+ // Match 1 or more non-path separators
217
+ for (; j < len; ++j) {
218
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
219
+ break;
220
+ }
221
+ if (j === len) {
222
+ // We matched a UNC root only
223
+ // Return the normalized version of the UNC root since there
224
+ // is nothing left to process
225
+ return `\\\\${firstPart}\\${path.slice(last)}\\`;
226
+ }
227
+ else if (j !== last) {
228
+ // We matched a UNC root with leftovers
229
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
230
+ rootEnd = j;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ else {
236
+ rootEnd = 1;
237
+ }
238
+ }
239
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
240
+ // Possible device root
241
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
242
+ device = path.slice(0, 2);
243
+ rootEnd = 2;
244
+ if (len > 2) {
245
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
246
+ // Treat separator following drive name as an absolute path
247
+ // indicator
248
+ isAbsolute = true;
249
+ rootEnd = 3;
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ else if ((0, _util_js_1.isPathSeparator)(code)) {
256
+ // `path` contains just a path separator, exit early to avoid unnecessary
257
+ // work
258
+ return "\\";
259
+ }
260
+ let tail;
261
+ if (rootEnd < len) {
262
+ tail = (0, _util_js_1.normalizeString)(path.slice(rootEnd), !isAbsolute, "\\", _util_js_1.isPathSeparator);
263
+ }
264
+ else {
265
+ tail = "";
266
+ }
267
+ if (tail.length === 0 && !isAbsolute)
268
+ tail = ".";
269
+ if (tail.length > 0 && (0, _util_js_1.isPathSeparator)(path.charCodeAt(len - 1))) {
270
+ tail += "\\";
271
+ }
272
+ if (device === undefined) {
273
+ if (isAbsolute) {
274
+ if (tail.length > 0)
275
+ return `\\${tail}`;
276
+ else
277
+ return "\\";
278
+ }
279
+ else if (tail.length > 0) {
280
+ return tail;
281
+ }
282
+ else {
283
+ return "";
284
+ }
285
+ }
286
+ else if (isAbsolute) {
287
+ if (tail.length > 0)
288
+ return `${device}\\${tail}`;
289
+ else
290
+ return `${device}\\`;
291
+ }
292
+ else if (tail.length > 0) {
293
+ return device + tail;
294
+ }
295
+ else {
296
+ return device;
297
+ }
298
+ }
299
+ exports.normalize = normalize;
300
+ /**
301
+ * Verifies whether path is absolute
302
+ * @param path to verify
303
+ */
304
+ function isAbsolute(path) {
305
+ (0, _util_js_1.assertPath)(path);
306
+ const len = path.length;
307
+ if (len === 0)
308
+ return false;
309
+ const code = path.charCodeAt(0);
310
+ if ((0, _util_js_1.isPathSeparator)(code)) {
311
+ return true;
312
+ }
313
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
314
+ // Possible device root
315
+ if (len > 2 && path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
316
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2)))
317
+ return true;
318
+ }
319
+ }
320
+ return false;
321
+ }
322
+ exports.isAbsolute = isAbsolute;
323
+ /**
324
+ * Join all given a sequence of `paths`,then normalizes the resulting path.
325
+ * @param paths to be joined and normalized
326
+ */
327
+ function join(...paths) {
328
+ const pathsCount = paths.length;
329
+ if (pathsCount === 0)
330
+ return ".";
331
+ let joined;
332
+ let firstPart = null;
333
+ for (let i = 0; i < pathsCount; ++i) {
334
+ const path = paths[i];
335
+ (0, _util_js_1.assertPath)(path);
336
+ if (path.length > 0) {
337
+ if (joined === undefined)
338
+ joined = firstPart = path;
339
+ else
340
+ joined += `\\${path}`;
341
+ }
342
+ }
343
+ if (joined === undefined)
344
+ return ".";
345
+ // Make sure that the joined path doesn't start with two slashes, because
346
+ // normalize() will mistake it for an UNC path then.
347
+ //
348
+ // This step is skipped when it is very clear that the user actually
349
+ // intended to point at an UNC path. This is assumed when the first
350
+ // non-empty string arguments starts with exactly two slashes followed by
351
+ // at least one more non-slash character.
352
+ //
353
+ // Note that for normalize() to treat a path as an UNC path it needs to
354
+ // have at least 2 components, so we don't filter for that here.
355
+ // This means that the user can use join to construct UNC paths from
356
+ // a server name and a share name; for example:
357
+ // path.join('//server', 'share') -> '\\\\server\\share\\')
358
+ let needsReplace = true;
359
+ let slashCount = 0;
360
+ (0, assert_js_1.assert)(firstPart != null);
361
+ if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(0))) {
362
+ ++slashCount;
363
+ const firstLen = firstPart.length;
364
+ if (firstLen > 1) {
365
+ if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(1))) {
366
+ ++slashCount;
367
+ if (firstLen > 2) {
368
+ if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(2)))
369
+ ++slashCount;
370
+ else {
371
+ // We matched a UNC path in the first part
372
+ needsReplace = false;
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+ if (needsReplace) {
379
+ // Find any more consecutive slashes we need to replace
380
+ for (; slashCount < joined.length; ++slashCount) {
381
+ if (!(0, _util_js_1.isPathSeparator)(joined.charCodeAt(slashCount)))
382
+ break;
383
+ }
384
+ // Replace the slashes if needed
385
+ if (slashCount >= 2)
386
+ joined = `\\${joined.slice(slashCount)}`;
387
+ }
388
+ return normalize(joined);
389
+ }
390
+ exports.join = join;
391
+ /**
392
+ * It will solve the relative path from `from` to `to`, for instance:
393
+ * from = 'C:\\orandea\\test\\aaa'
394
+ * to = 'C:\\orandea\\impl\\bbb'
395
+ * The output of the function should be: '..\\..\\impl\\bbb'
396
+ * @param from relative path
397
+ * @param to relative path
398
+ */
399
+ function relative(from, to) {
400
+ (0, _util_js_1.assertPath)(from);
401
+ (0, _util_js_1.assertPath)(to);
402
+ if (from === to)
403
+ return "";
404
+ const fromOrig = resolve(from);
405
+ const toOrig = resolve(to);
406
+ if (fromOrig === toOrig)
407
+ return "";
408
+ from = fromOrig.toLowerCase();
409
+ to = toOrig.toLowerCase();
410
+ if (from === to)
411
+ return "";
412
+ // Trim any leading backslashes
413
+ let fromStart = 0;
414
+ let fromEnd = from.length;
415
+ for (; fromStart < fromEnd; ++fromStart) {
416
+ if (from.charCodeAt(fromStart) !== _constants_js_1.CHAR_BACKWARD_SLASH)
417
+ break;
418
+ }
419
+ // Trim trailing backslashes (applicable to UNC paths only)
420
+ for (; fromEnd - 1 > fromStart; --fromEnd) {
421
+ if (from.charCodeAt(fromEnd - 1) !== _constants_js_1.CHAR_BACKWARD_SLASH)
422
+ break;
423
+ }
424
+ const fromLen = fromEnd - fromStart;
425
+ // Trim any leading backslashes
426
+ let toStart = 0;
427
+ let toEnd = to.length;
428
+ for (; toStart < toEnd; ++toStart) {
429
+ if (to.charCodeAt(toStart) !== _constants_js_1.CHAR_BACKWARD_SLASH)
430
+ break;
431
+ }
432
+ // Trim trailing backslashes (applicable to UNC paths only)
433
+ for (; toEnd - 1 > toStart; --toEnd) {
434
+ if (to.charCodeAt(toEnd - 1) !== _constants_js_1.CHAR_BACKWARD_SLASH)
435
+ break;
436
+ }
437
+ const toLen = toEnd - toStart;
438
+ // Compare paths to find the longest common path from root
439
+ const length = fromLen < toLen ? fromLen : toLen;
440
+ let lastCommonSep = -1;
441
+ let i = 0;
442
+ for (; i <= length; ++i) {
443
+ if (i === length) {
444
+ if (toLen > length) {
445
+ if (to.charCodeAt(toStart + i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
446
+ // We get here if `from` is the exact base path for `to`.
447
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
448
+ return toOrig.slice(toStart + i + 1);
449
+ }
450
+ else if (i === 2) {
451
+ // We get here if `from` is the device root.
452
+ // For example: from='C:\\'; to='C:\\foo'
453
+ return toOrig.slice(toStart + i);
454
+ }
455
+ }
456
+ if (fromLen > length) {
457
+ if (from.charCodeAt(fromStart + i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
458
+ // We get here if `to` is the exact base path for `from`.
459
+ // For example: from='C:\\foo\\bar'; to='C:\\foo'
460
+ lastCommonSep = i;
461
+ }
462
+ else if (i === 2) {
463
+ // We get here if `to` is the device root.
464
+ // For example: from='C:\\foo\\bar'; to='C:\\'
465
+ lastCommonSep = 3;
466
+ }
467
+ }
468
+ break;
469
+ }
470
+ const fromCode = from.charCodeAt(fromStart + i);
471
+ const toCode = to.charCodeAt(toStart + i);
472
+ if (fromCode !== toCode)
473
+ break;
474
+ else if (fromCode === _constants_js_1.CHAR_BACKWARD_SLASH)
475
+ lastCommonSep = i;
476
+ }
477
+ // We found a mismatch before the first common path separator was seen, so
478
+ // return the original `to`.
479
+ if (i !== length && lastCommonSep === -1) {
480
+ return toOrig;
481
+ }
482
+ let out = "";
483
+ if (lastCommonSep === -1)
484
+ lastCommonSep = 0;
485
+ // Generate the relative path based on the path difference between `to` and
486
+ // `from`
487
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
488
+ if (i === fromEnd || from.charCodeAt(i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
489
+ if (out.length === 0)
490
+ out += "..";
491
+ else
492
+ out += "\\..";
493
+ }
494
+ }
495
+ // Lastly, append the rest of the destination (`to`) path that comes after
496
+ // the common path parts
497
+ if (out.length > 0) {
498
+ return out + toOrig.slice(toStart + lastCommonSep, toEnd);
499
+ }
500
+ else {
501
+ toStart += lastCommonSep;
502
+ if (toOrig.charCodeAt(toStart) === _constants_js_1.CHAR_BACKWARD_SLASH)
503
+ ++toStart;
504
+ return toOrig.slice(toStart, toEnd);
505
+ }
506
+ }
507
+ exports.relative = relative;
508
+ /**
509
+ * Resolves path to a namespace path
510
+ * @param path to resolve to namespace
511
+ */
512
+ function toNamespacedPath(path) {
513
+ // Note: this will *probably* throw somewhere.
514
+ if (typeof path !== "string")
515
+ return path;
516
+ if (path.length === 0)
517
+ return "";
518
+ const resolvedPath = resolve(path);
519
+ if (resolvedPath.length >= 3) {
520
+ if (resolvedPath.charCodeAt(0) === _constants_js_1.CHAR_BACKWARD_SLASH) {
521
+ // Possible UNC root
522
+ if (resolvedPath.charCodeAt(1) === _constants_js_1.CHAR_BACKWARD_SLASH) {
523
+ const code = resolvedPath.charCodeAt(2);
524
+ if (code !== _constants_js_1.CHAR_QUESTION_MARK && code !== _constants_js_1.CHAR_DOT) {
525
+ // Matched non-long UNC root, convert the path to a long UNC path
526
+ return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
527
+ }
528
+ }
529
+ }
530
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(resolvedPath.charCodeAt(0))) {
531
+ // Possible device root
532
+ if (resolvedPath.charCodeAt(1) === _constants_js_1.CHAR_COLON &&
533
+ resolvedPath.charCodeAt(2) === _constants_js_1.CHAR_BACKWARD_SLASH) {
534
+ // Matched device root, convert the path to a long UNC path
535
+ return `\\\\?\\${resolvedPath}`;
536
+ }
537
+ }
538
+ }
539
+ return path;
540
+ }
541
+ exports.toNamespacedPath = toNamespacedPath;
542
+ /**
543
+ * Return the directory name of a `path`.
544
+ * @param path to determine name for
545
+ */
546
+ function dirname(path) {
547
+ (0, _util_js_1.assertPath)(path);
548
+ const len = path.length;
549
+ if (len === 0)
550
+ return ".";
551
+ let rootEnd = -1;
552
+ let end = -1;
553
+ let matchedSlash = true;
554
+ let offset = 0;
555
+ const code = path.charCodeAt(0);
556
+ // Try to match a root
557
+ if (len > 1) {
558
+ if ((0, _util_js_1.isPathSeparator)(code)) {
559
+ // Possible UNC root
560
+ rootEnd = offset = 1;
561
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
562
+ // Matched double path separator at beginning
563
+ let j = 2;
564
+ let last = j;
565
+ // Match 1 or more non-path separators
566
+ for (; j < len; ++j) {
567
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
568
+ break;
569
+ }
570
+ if (j < len && j !== last) {
571
+ // Matched!
572
+ last = j;
573
+ // Match 1 or more path separators
574
+ for (; j < len; ++j) {
575
+ if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
576
+ break;
577
+ }
578
+ if (j < len && j !== last) {
579
+ // Matched!
580
+ last = j;
581
+ // Match 1 or more non-path separators
582
+ for (; j < len; ++j) {
583
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
584
+ break;
585
+ }
586
+ if (j === len) {
587
+ // We matched a UNC root only
588
+ return path;
589
+ }
590
+ if (j !== last) {
591
+ // We matched a UNC root with leftovers
592
+ // Offset by 1 to include the separator after the UNC root to
593
+ // treat it as a "normal root" on top of a (UNC) root
594
+ rootEnd = offset = j + 1;
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
601
+ // Possible device root
602
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
603
+ rootEnd = offset = 2;
604
+ if (len > 2) {
605
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2)))
606
+ rootEnd = offset = 3;
607
+ }
608
+ }
609
+ }
610
+ }
611
+ else if ((0, _util_js_1.isPathSeparator)(code)) {
612
+ // `path` contains just a path separator, exit early to avoid
613
+ // unnecessary work
614
+ return path;
615
+ }
616
+ for (let i = len - 1; i >= offset; --i) {
617
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(i))) {
618
+ if (!matchedSlash) {
619
+ end = i;
620
+ break;
621
+ }
622
+ }
623
+ else {
624
+ // We saw the first non-path separator
625
+ matchedSlash = false;
626
+ }
627
+ }
628
+ if (end === -1) {
629
+ if (rootEnd === -1)
630
+ return ".";
631
+ else
632
+ end = rootEnd;
633
+ }
634
+ return path.slice(0, end);
635
+ }
636
+ exports.dirname = dirname;
637
+ /**
638
+ * Return the last portion of a `path`. Trailing directory separators are ignored.
639
+ * @param path to process
640
+ * @param ext of path directory
641
+ */
642
+ function basename(path, ext = "") {
643
+ if (ext !== undefined && typeof ext !== "string") {
644
+ throw new TypeError('"ext" argument must be a string');
645
+ }
646
+ (0, _util_js_1.assertPath)(path);
647
+ let start = 0;
648
+ let end = -1;
649
+ let matchedSlash = true;
650
+ let i;
651
+ // Check for a drive letter prefix so as not to mistake the following
652
+ // path separator as an extra separator at the end of the path that can be
653
+ // disregarded
654
+ if (path.length >= 2) {
655
+ const drive = path.charCodeAt(0);
656
+ if ((0, _util_js_1.isWindowsDeviceRoot)(drive)) {
657
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON)
658
+ start = 2;
659
+ }
660
+ }
661
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
662
+ if (ext.length === path.length && ext === path)
663
+ return "";
664
+ let extIdx = ext.length - 1;
665
+ let firstNonSlashEnd = -1;
666
+ for (i = path.length - 1; i >= start; --i) {
667
+ const code = path.charCodeAt(i);
668
+ if ((0, _util_js_1.isPathSeparator)(code)) {
669
+ // If we reached a path separator that was not part of a set of path
670
+ // separators at the end of the string, stop now
671
+ if (!matchedSlash) {
672
+ start = i + 1;
673
+ break;
674
+ }
675
+ }
676
+ else {
677
+ if (firstNonSlashEnd === -1) {
678
+ // We saw the first non-path separator, remember this index in case
679
+ // we need it if the extension ends up not matching
680
+ matchedSlash = false;
681
+ firstNonSlashEnd = i + 1;
682
+ }
683
+ if (extIdx >= 0) {
684
+ // Try to match the explicit extension
685
+ if (code === ext.charCodeAt(extIdx)) {
686
+ if (--extIdx === -1) {
687
+ // We matched the extension, so mark this as the end of our path
688
+ // component
689
+ end = i;
690
+ }
691
+ }
692
+ else {
693
+ // Extension does not match, so our result is the entire path
694
+ // component
695
+ extIdx = -1;
696
+ end = firstNonSlashEnd;
697
+ }
698
+ }
699
+ }
700
+ }
701
+ if (start === end)
702
+ end = firstNonSlashEnd;
703
+ else if (end === -1)
704
+ end = path.length;
705
+ return path.slice(start, end);
706
+ }
707
+ else {
708
+ for (i = path.length - 1; i >= start; --i) {
709
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(i))) {
710
+ // If we reached a path separator that was not part of a set of path
711
+ // separators at the end of the string, stop now
712
+ if (!matchedSlash) {
713
+ start = i + 1;
714
+ break;
715
+ }
716
+ }
717
+ else if (end === -1) {
718
+ // We saw the first non-path separator, mark this as the end of our
719
+ // path component
720
+ matchedSlash = false;
721
+ end = i + 1;
722
+ }
723
+ }
724
+ if (end === -1)
725
+ return "";
726
+ return path.slice(start, end);
727
+ }
728
+ }
729
+ exports.basename = basename;
730
+ /**
731
+ * Return the extension of the `path`.
732
+ * @param path with extension
733
+ */
734
+ function extname(path) {
735
+ (0, _util_js_1.assertPath)(path);
736
+ let start = 0;
737
+ let startDot = -1;
738
+ let startPart = 0;
739
+ let end = -1;
740
+ let matchedSlash = true;
741
+ // Track the state of characters (if any) we see before our first dot and
742
+ // after any path separator we find
743
+ let preDotState = 0;
744
+ // Check for a drive letter prefix so as not to mistake the following
745
+ // path separator as an extra separator at the end of the path that can be
746
+ // disregarded
747
+ if (path.length >= 2 &&
748
+ path.charCodeAt(1) === _constants_js_1.CHAR_COLON &&
749
+ (0, _util_js_1.isWindowsDeviceRoot)(path.charCodeAt(0))) {
750
+ start = startPart = 2;
751
+ }
752
+ for (let i = path.length - 1; i >= start; --i) {
753
+ const code = path.charCodeAt(i);
754
+ if ((0, _util_js_1.isPathSeparator)(code)) {
755
+ // If we reached a path separator that was not part of a set of path
756
+ // separators at the end of the string, stop now
757
+ if (!matchedSlash) {
758
+ startPart = i + 1;
759
+ break;
760
+ }
761
+ continue;
762
+ }
763
+ if (end === -1) {
764
+ // We saw the first non-path separator, mark this as the end of our
765
+ // extension
766
+ matchedSlash = false;
767
+ end = i + 1;
768
+ }
769
+ if (code === _constants_js_1.CHAR_DOT) {
770
+ // If this is our first dot, mark it as the start of our extension
771
+ if (startDot === -1)
772
+ startDot = i;
773
+ else if (preDotState !== 1)
774
+ preDotState = 1;
775
+ }
776
+ else if (startDot !== -1) {
777
+ // We saw a non-dot and non-path separator before our dot, so we should
778
+ // have a good chance at having a non-empty extension
779
+ preDotState = -1;
780
+ }
781
+ }
782
+ if (startDot === -1 ||
783
+ end === -1 ||
784
+ // We saw a non-dot character immediately before the dot
785
+ preDotState === 0 ||
786
+ // The (right-most) trimmed path component is exactly '..'
787
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
788
+ return "";
789
+ }
790
+ return path.slice(startDot, end);
791
+ }
792
+ exports.extname = extname;
793
+ /**
794
+ * Generate a path from `FormatInputPathObject` object.
795
+ * @param pathObject with path
796
+ */
797
+ function format(pathObject) {
798
+ if (pathObject === null || typeof pathObject !== "object") {
799
+ throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`);
800
+ }
801
+ return (0, _util_js_1._format)("\\", pathObject);
802
+ }
803
+ exports.format = format;
804
+ /**
805
+ * Return a `ParsedPath` object of the `path`.
806
+ * @param path to process
807
+ */
808
+ function parse(path) {
809
+ (0, _util_js_1.assertPath)(path);
810
+ const ret = { root: "", dir: "", base: "", ext: "", name: "" };
811
+ const len = path.length;
812
+ if (len === 0)
813
+ return ret;
814
+ let rootEnd = 0;
815
+ let code = path.charCodeAt(0);
816
+ // Try to match a root
817
+ if (len > 1) {
818
+ if ((0, _util_js_1.isPathSeparator)(code)) {
819
+ // Possible UNC root
820
+ rootEnd = 1;
821
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
822
+ // Matched double path separator at beginning
823
+ let j = 2;
824
+ let last = j;
825
+ // Match 1 or more non-path separators
826
+ for (; j < len; ++j) {
827
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
828
+ break;
829
+ }
830
+ if (j < len && j !== last) {
831
+ // Matched!
832
+ last = j;
833
+ // Match 1 or more path separators
834
+ for (; j < len; ++j) {
835
+ if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
836
+ break;
837
+ }
838
+ if (j < len && j !== last) {
839
+ // Matched!
840
+ last = j;
841
+ // Match 1 or more non-path separators
842
+ for (; j < len; ++j) {
843
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
844
+ break;
845
+ }
846
+ if (j === len) {
847
+ // We matched a UNC root only
848
+ rootEnd = j;
849
+ }
850
+ else if (j !== last) {
851
+ // We matched a UNC root with leftovers
852
+ rootEnd = j + 1;
853
+ }
854
+ }
855
+ }
856
+ }
857
+ }
858
+ else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
859
+ // Possible device root
860
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
861
+ rootEnd = 2;
862
+ if (len > 2) {
863
+ if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
864
+ if (len === 3) {
865
+ // `path` contains just a drive root, exit early to avoid
866
+ // unnecessary work
867
+ ret.root = ret.dir = path;
868
+ return ret;
869
+ }
870
+ rootEnd = 3;
871
+ }
872
+ }
873
+ else {
874
+ // `path` contains just a drive root, exit early to avoid
875
+ // unnecessary work
876
+ ret.root = ret.dir = path;
877
+ return ret;
878
+ }
879
+ }
880
+ }
881
+ }
882
+ else if ((0, _util_js_1.isPathSeparator)(code)) {
883
+ // `path` contains just a path separator, exit early to avoid
884
+ // unnecessary work
885
+ ret.root = ret.dir = path;
886
+ return ret;
887
+ }
888
+ if (rootEnd > 0)
889
+ ret.root = path.slice(0, rootEnd);
890
+ let startDot = -1;
891
+ let startPart = rootEnd;
892
+ let end = -1;
893
+ let matchedSlash = true;
894
+ let i = path.length - 1;
895
+ // Track the state of characters (if any) we see before our first dot and
896
+ // after any path separator we find
897
+ let preDotState = 0;
898
+ // Get non-dir info
899
+ for (; i >= rootEnd; --i) {
900
+ code = path.charCodeAt(i);
901
+ if ((0, _util_js_1.isPathSeparator)(code)) {
902
+ // If we reached a path separator that was not part of a set of path
903
+ // separators at the end of the string, stop now
904
+ if (!matchedSlash) {
905
+ startPart = i + 1;
906
+ break;
907
+ }
908
+ continue;
909
+ }
910
+ if (end === -1) {
911
+ // We saw the first non-path separator, mark this as the end of our
912
+ // extension
913
+ matchedSlash = false;
914
+ end = i + 1;
915
+ }
916
+ if (code === _constants_js_1.CHAR_DOT) {
917
+ // If this is our first dot, mark it as the start of our extension
918
+ if (startDot === -1)
919
+ startDot = i;
920
+ else if (preDotState !== 1)
921
+ preDotState = 1;
922
+ }
923
+ else if (startDot !== -1) {
924
+ // We saw a non-dot and non-path separator before our dot, so we should
925
+ // have a good chance at having a non-empty extension
926
+ preDotState = -1;
927
+ }
928
+ }
929
+ if (startDot === -1 ||
930
+ end === -1 ||
931
+ // We saw a non-dot character immediately before the dot
932
+ preDotState === 0 ||
933
+ // The (right-most) trimmed path component is exactly '..'
934
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
935
+ if (end !== -1) {
936
+ ret.base = ret.name = path.slice(startPart, end);
937
+ }
938
+ }
939
+ else {
940
+ ret.name = path.slice(startPart, startDot);
941
+ ret.base = path.slice(startPart, end);
942
+ ret.ext = path.slice(startDot, end);
943
+ }
944
+ // If the directory is the root, use the entire root as the `dir` including
945
+ // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
946
+ // trailing slash (`C:\abc\def` -> `C:\abc`).
947
+ if (startPart > 0 && startPart !== rootEnd) {
948
+ ret.dir = path.slice(0, startPart - 1);
949
+ }
950
+ else
951
+ ret.dir = ret.root;
952
+ return ret;
953
+ }
954
+ exports.parse = parse;
955
+ /**
956
+ * Converts a file URL to a path string.
957
+ *
958
+ * ```ts
959
+ * import { fromFileUrl } from "./win32.ts";
960
+ * fromFileUrl("file:///home/foo"); // "\\home\\foo"
961
+ * fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
962
+ * fromFileUrl("file://localhost/home/foo"); // "\\\\localhost\\home\\foo"
963
+ * ```
964
+ * @param url of a file URL
965
+ */
966
+ function fromFileUrl(url) {
967
+ url = url instanceof URL ? url : new URL(url);
968
+ if (url.protocol != "file:") {
969
+ throw new TypeError("Must be a file URL.");
970
+ }
971
+ let path = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\");
972
+ if (url.hostname != "") {
973
+ // Note: The `URL` implementation guarantees that the drive letter and
974
+ // hostname are mutually exclusive. Otherwise it would not have been valid
975
+ // to append the hostname and path like this.
976
+ path = `\\\\${url.hostname}${path}`;
977
+ }
978
+ return path;
979
+ }
980
+ exports.fromFileUrl = fromFileUrl;
981
+ /**
982
+ * Converts a path string to a file URL.
983
+ *
984
+ * ```ts
985
+ * import { toFileUrl } from "./win32.ts";
986
+ * toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
987
+ * toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
988
+ * toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
989
+ * ```
990
+ * @param path to convert to file URL
991
+ */
992
+ function toFileUrl(path) {
993
+ if (!isAbsolute(path)) {
994
+ throw new TypeError("Must be an absolute path.");
995
+ }
996
+ const [, hostname, pathname] = path.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/);
997
+ const url = new URL("file:///");
998
+ url.pathname = (0, _util_js_1.encodeWhitespace)(pathname.replace(/%/g, "%25"));
999
+ if (hostname != null && hostname != "localhost") {
1000
+ url.hostname = hostname;
1001
+ if (!url.hostname) {
1002
+ throw new TypeError("Invalid hostname.");
1003
+ }
1004
+ }
1005
+ return url;
1006
+ }
1007
+ exports.toFileUrl = toFileUrl;
1008
+ });