keep-a-changelog 0.10.4 → 2.0.0-beta

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