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,538 @@
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"], 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
+ exports.sep = "/";
36
+ exports.delimiter = ":";
37
+ // path.resolve([from ...], to)
38
+ /**
39
+ * Resolves `pathSegments` into an absolute path.
40
+ * @param pathSegments an array of path segments
41
+ */
42
+ function resolve(...pathSegments) {
43
+ let resolvedPath = "";
44
+ let resolvedAbsolute = false;
45
+ for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
46
+ let path;
47
+ if (i >= 0)
48
+ path = pathSegments[i];
49
+ else {
50
+ // deno-lint-ignore no-explicit-any
51
+ const { Deno } = dntShim.dntGlobalThis;
52
+ if (typeof Deno?.cwd !== "function") {
53
+ throw new TypeError("Resolved a relative path without a CWD.");
54
+ }
55
+ path = Deno.cwd();
56
+ }
57
+ (0, _util_js_1.assertPath)(path);
58
+ // Skip empty entries
59
+ if (path.length === 0) {
60
+ continue;
61
+ }
62
+ resolvedPath = `${path}/${resolvedPath}`;
63
+ resolvedAbsolute = path.charCodeAt(0) === _constants_js_1.CHAR_FORWARD_SLASH;
64
+ }
65
+ // At this point the path should be resolved to a full absolute path, but
66
+ // handle relative paths to be safe (might happen when process.cwd() fails)
67
+ // Normalize the path
68
+ resolvedPath = (0, _util_js_1.normalizeString)(resolvedPath, !resolvedAbsolute, "/", _util_js_1.isPosixPathSeparator);
69
+ if (resolvedAbsolute) {
70
+ if (resolvedPath.length > 0)
71
+ return `/${resolvedPath}`;
72
+ else
73
+ return "/";
74
+ }
75
+ else if (resolvedPath.length > 0)
76
+ return resolvedPath;
77
+ else
78
+ return ".";
79
+ }
80
+ exports.resolve = resolve;
81
+ /**
82
+ * Normalize the `path`, resolving `'..'` and `'.'` segments.
83
+ * @param path to be normalized
84
+ */
85
+ function normalize(path) {
86
+ (0, _util_js_1.assertPath)(path);
87
+ if (path.length === 0)
88
+ return ".";
89
+ const isAbsolute = path.charCodeAt(0) === _constants_js_1.CHAR_FORWARD_SLASH;
90
+ const trailingSeparator = path.charCodeAt(path.length - 1) === _constants_js_1.CHAR_FORWARD_SLASH;
91
+ // Normalize the path
92
+ path = (0, _util_js_1.normalizeString)(path, !isAbsolute, "/", _util_js_1.isPosixPathSeparator);
93
+ if (path.length === 0 && !isAbsolute)
94
+ path = ".";
95
+ if (path.length > 0 && trailingSeparator)
96
+ path += "/";
97
+ if (isAbsolute)
98
+ return `/${path}`;
99
+ return path;
100
+ }
101
+ exports.normalize = normalize;
102
+ /**
103
+ * Verifies whether provided path is absolute
104
+ * @param path to be verified as absolute
105
+ */
106
+ function isAbsolute(path) {
107
+ (0, _util_js_1.assertPath)(path);
108
+ return path.length > 0 && path.charCodeAt(0) === _constants_js_1.CHAR_FORWARD_SLASH;
109
+ }
110
+ exports.isAbsolute = isAbsolute;
111
+ /**
112
+ * Join all given a sequence of `paths`,then normalizes the resulting path.
113
+ * @param paths to be joined and normalized
114
+ */
115
+ function join(...paths) {
116
+ if (paths.length === 0)
117
+ return ".";
118
+ let joined;
119
+ for (let i = 0, len = paths.length; i < len; ++i) {
120
+ const path = paths[i];
121
+ (0, _util_js_1.assertPath)(path);
122
+ if (path.length > 0) {
123
+ if (!joined)
124
+ joined = path;
125
+ else
126
+ joined += `/${path}`;
127
+ }
128
+ }
129
+ if (!joined)
130
+ return ".";
131
+ return normalize(joined);
132
+ }
133
+ exports.join = join;
134
+ /**
135
+ * Return the relative path from `from` to `to` based on current working directory.
136
+ * @param from path in current working directory
137
+ * @param to path in current working directory
138
+ */
139
+ function relative(from, to) {
140
+ (0, _util_js_1.assertPath)(from);
141
+ (0, _util_js_1.assertPath)(to);
142
+ if (from === to)
143
+ return "";
144
+ from = resolve(from);
145
+ to = resolve(to);
146
+ if (from === to)
147
+ return "";
148
+ // Trim any leading backslashes
149
+ let fromStart = 1;
150
+ const fromEnd = from.length;
151
+ for (; fromStart < fromEnd; ++fromStart) {
152
+ if (from.charCodeAt(fromStart) !== _constants_js_1.CHAR_FORWARD_SLASH)
153
+ break;
154
+ }
155
+ const fromLen = fromEnd - fromStart;
156
+ // Trim any leading backslashes
157
+ let toStart = 1;
158
+ const toEnd = to.length;
159
+ for (; toStart < toEnd; ++toStart) {
160
+ if (to.charCodeAt(toStart) !== _constants_js_1.CHAR_FORWARD_SLASH)
161
+ break;
162
+ }
163
+ const toLen = toEnd - toStart;
164
+ // Compare paths to find the longest common path from root
165
+ const length = fromLen < toLen ? fromLen : toLen;
166
+ let lastCommonSep = -1;
167
+ let i = 0;
168
+ for (; i <= length; ++i) {
169
+ if (i === length) {
170
+ if (toLen > length) {
171
+ if (to.charCodeAt(toStart + i) === _constants_js_1.CHAR_FORWARD_SLASH) {
172
+ // We get here if `from` is the exact base path for `to`.
173
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
174
+ return to.slice(toStart + i + 1);
175
+ }
176
+ else if (i === 0) {
177
+ // We get here if `from` is the root
178
+ // For example: from='/'; to='/foo'
179
+ return to.slice(toStart + i);
180
+ }
181
+ }
182
+ else if (fromLen > length) {
183
+ if (from.charCodeAt(fromStart + i) === _constants_js_1.CHAR_FORWARD_SLASH) {
184
+ // We get here if `to` is the exact base path for `from`.
185
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
186
+ lastCommonSep = i;
187
+ }
188
+ else if (i === 0) {
189
+ // We get here if `to` is the root.
190
+ // For example: from='/foo'; to='/'
191
+ lastCommonSep = 0;
192
+ }
193
+ }
194
+ break;
195
+ }
196
+ const fromCode = from.charCodeAt(fromStart + i);
197
+ const toCode = to.charCodeAt(toStart + i);
198
+ if (fromCode !== toCode)
199
+ break;
200
+ else if (fromCode === _constants_js_1.CHAR_FORWARD_SLASH)
201
+ lastCommonSep = i;
202
+ }
203
+ let out = "";
204
+ // Generate the relative path based on the path difference between `to`
205
+ // and `from`
206
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
207
+ if (i === fromEnd || from.charCodeAt(i) === _constants_js_1.CHAR_FORWARD_SLASH) {
208
+ if (out.length === 0)
209
+ out += "..";
210
+ else
211
+ out += "/..";
212
+ }
213
+ }
214
+ // Lastly, append the rest of the destination (`to`) path that comes after
215
+ // the common path parts
216
+ if (out.length > 0)
217
+ return out + to.slice(toStart + lastCommonSep);
218
+ else {
219
+ toStart += lastCommonSep;
220
+ if (to.charCodeAt(toStart) === _constants_js_1.CHAR_FORWARD_SLASH)
221
+ ++toStart;
222
+ return to.slice(toStart);
223
+ }
224
+ }
225
+ exports.relative = relative;
226
+ /**
227
+ * Resolves path to a namespace path
228
+ * @param path to resolve to namespace
229
+ */
230
+ function toNamespacedPath(path) {
231
+ // Non-op on posix systems
232
+ return path;
233
+ }
234
+ exports.toNamespacedPath = toNamespacedPath;
235
+ /**
236
+ * Return the directory name of a `path`.
237
+ * @param path to determine name for
238
+ */
239
+ function dirname(path) {
240
+ (0, _util_js_1.assertPath)(path);
241
+ if (path.length === 0)
242
+ return ".";
243
+ const hasRoot = path.charCodeAt(0) === _constants_js_1.CHAR_FORWARD_SLASH;
244
+ let end = -1;
245
+ let matchedSlash = true;
246
+ for (let i = path.length - 1; i >= 1; --i) {
247
+ if (path.charCodeAt(i) === _constants_js_1.CHAR_FORWARD_SLASH) {
248
+ if (!matchedSlash) {
249
+ end = i;
250
+ break;
251
+ }
252
+ }
253
+ else {
254
+ // We saw the first non-path separator
255
+ matchedSlash = false;
256
+ }
257
+ }
258
+ if (end === -1)
259
+ return hasRoot ? "/" : ".";
260
+ if (hasRoot && end === 1)
261
+ return "//";
262
+ return path.slice(0, end);
263
+ }
264
+ exports.dirname = dirname;
265
+ /**
266
+ * Return the last portion of a `path`. Trailing directory separators are ignored.
267
+ * @param path to process
268
+ * @param ext of path directory
269
+ */
270
+ function basename(path, ext = "") {
271
+ if (ext !== undefined && typeof ext !== "string") {
272
+ throw new TypeError('"ext" argument must be a string');
273
+ }
274
+ (0, _util_js_1.assertPath)(path);
275
+ let start = 0;
276
+ let end = -1;
277
+ let matchedSlash = true;
278
+ let i;
279
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
280
+ if (ext.length === path.length && ext === path)
281
+ return "";
282
+ let extIdx = ext.length - 1;
283
+ let firstNonSlashEnd = -1;
284
+ for (i = path.length - 1; i >= 0; --i) {
285
+ const code = path.charCodeAt(i);
286
+ if (code === _constants_js_1.CHAR_FORWARD_SLASH) {
287
+ // If we reached a path separator that was not part of a set of path
288
+ // separators at the end of the string, stop now
289
+ if (!matchedSlash) {
290
+ start = i + 1;
291
+ break;
292
+ }
293
+ }
294
+ else {
295
+ if (firstNonSlashEnd === -1) {
296
+ // We saw the first non-path separator, remember this index in case
297
+ // we need it if the extension ends up not matching
298
+ matchedSlash = false;
299
+ firstNonSlashEnd = i + 1;
300
+ }
301
+ if (extIdx >= 0) {
302
+ // Try to match the explicit extension
303
+ if (code === ext.charCodeAt(extIdx)) {
304
+ if (--extIdx === -1) {
305
+ // We matched the extension, so mark this as the end of our path
306
+ // component
307
+ end = i;
308
+ }
309
+ }
310
+ else {
311
+ // Extension does not match, so our result is the entire path
312
+ // component
313
+ extIdx = -1;
314
+ end = firstNonSlashEnd;
315
+ }
316
+ }
317
+ }
318
+ }
319
+ if (start === end)
320
+ end = firstNonSlashEnd;
321
+ else if (end === -1)
322
+ end = path.length;
323
+ return path.slice(start, end);
324
+ }
325
+ else {
326
+ for (i = path.length - 1; i >= 0; --i) {
327
+ if (path.charCodeAt(i) === _constants_js_1.CHAR_FORWARD_SLASH) {
328
+ // If we reached a path separator that was not part of a set of path
329
+ // separators at the end of the string, stop now
330
+ if (!matchedSlash) {
331
+ start = i + 1;
332
+ break;
333
+ }
334
+ }
335
+ else if (end === -1) {
336
+ // We saw the first non-path separator, mark this as the end of our
337
+ // path component
338
+ matchedSlash = false;
339
+ end = i + 1;
340
+ }
341
+ }
342
+ if (end === -1)
343
+ return "";
344
+ return path.slice(start, end);
345
+ }
346
+ }
347
+ exports.basename = basename;
348
+ /**
349
+ * Return the extension of the `path`.
350
+ * @param path with extension
351
+ */
352
+ function extname(path) {
353
+ (0, _util_js_1.assertPath)(path);
354
+ let startDot = -1;
355
+ let startPart = 0;
356
+ let end = -1;
357
+ let matchedSlash = true;
358
+ // Track the state of characters (if any) we see before our first dot and
359
+ // after any path separator we find
360
+ let preDotState = 0;
361
+ for (let i = path.length - 1; i >= 0; --i) {
362
+ const code = path.charCodeAt(i);
363
+ if (code === _constants_js_1.CHAR_FORWARD_SLASH) {
364
+ // If we reached a path separator that was not part of a set of path
365
+ // separators at the end of the string, stop now
366
+ if (!matchedSlash) {
367
+ startPart = i + 1;
368
+ break;
369
+ }
370
+ continue;
371
+ }
372
+ if (end === -1) {
373
+ // We saw the first non-path separator, mark this as the end of our
374
+ // extension
375
+ matchedSlash = false;
376
+ end = i + 1;
377
+ }
378
+ if (code === _constants_js_1.CHAR_DOT) {
379
+ // If this is our first dot, mark it as the start of our extension
380
+ if (startDot === -1)
381
+ startDot = i;
382
+ else if (preDotState !== 1)
383
+ preDotState = 1;
384
+ }
385
+ else if (startDot !== -1) {
386
+ // We saw a non-dot and non-path separator before our dot, so we should
387
+ // have a good chance at having a non-empty extension
388
+ preDotState = -1;
389
+ }
390
+ }
391
+ if (startDot === -1 ||
392
+ end === -1 ||
393
+ // We saw a non-dot character immediately before the dot
394
+ preDotState === 0 ||
395
+ // The (right-most) trimmed path component is exactly '..'
396
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
397
+ return "";
398
+ }
399
+ return path.slice(startDot, end);
400
+ }
401
+ exports.extname = extname;
402
+ /**
403
+ * Generate a path from `FormatInputPathObject` object.
404
+ * @param pathObject with path
405
+ */
406
+ function format(pathObject) {
407
+ if (pathObject === null || typeof pathObject !== "object") {
408
+ throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`);
409
+ }
410
+ return (0, _util_js_1._format)("/", pathObject);
411
+ }
412
+ exports.format = format;
413
+ /**
414
+ * Return a `ParsedPath` object of the `path`.
415
+ * @param path to process
416
+ */
417
+ function parse(path) {
418
+ (0, _util_js_1.assertPath)(path);
419
+ const ret = { root: "", dir: "", base: "", ext: "", name: "" };
420
+ if (path.length === 0)
421
+ return ret;
422
+ const isAbsolute = path.charCodeAt(0) === _constants_js_1.CHAR_FORWARD_SLASH;
423
+ let start;
424
+ if (isAbsolute) {
425
+ ret.root = "/";
426
+ start = 1;
427
+ }
428
+ else {
429
+ start = 0;
430
+ }
431
+ let startDot = -1;
432
+ let startPart = 0;
433
+ let end = -1;
434
+ let matchedSlash = true;
435
+ let i = path.length - 1;
436
+ // Track the state of characters (if any) we see before our first dot and
437
+ // after any path separator we find
438
+ let preDotState = 0;
439
+ // Get non-dir info
440
+ for (; i >= start; --i) {
441
+ const code = path.charCodeAt(i);
442
+ if (code === _constants_js_1.CHAR_FORWARD_SLASH) {
443
+ // If we reached a path separator that was not part of a set of path
444
+ // separators at the end of the string, stop now
445
+ if (!matchedSlash) {
446
+ startPart = i + 1;
447
+ break;
448
+ }
449
+ continue;
450
+ }
451
+ if (end === -1) {
452
+ // We saw the first non-path separator, mark this as the end of our
453
+ // extension
454
+ matchedSlash = false;
455
+ end = i + 1;
456
+ }
457
+ if (code === _constants_js_1.CHAR_DOT) {
458
+ // If this is our first dot, mark it as the start of our extension
459
+ if (startDot === -1)
460
+ startDot = i;
461
+ else if (preDotState !== 1)
462
+ preDotState = 1;
463
+ }
464
+ else if (startDot !== -1) {
465
+ // We saw a non-dot and non-path separator before our dot, so we should
466
+ // have a good chance at having a non-empty extension
467
+ preDotState = -1;
468
+ }
469
+ }
470
+ if (startDot === -1 ||
471
+ end === -1 ||
472
+ // We saw a non-dot character immediately before the dot
473
+ preDotState === 0 ||
474
+ // The (right-most) trimmed path component is exactly '..'
475
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
476
+ if (end !== -1) {
477
+ if (startPart === 0 && isAbsolute) {
478
+ ret.base = ret.name = path.slice(1, end);
479
+ }
480
+ else {
481
+ ret.base = ret.name = path.slice(startPart, end);
482
+ }
483
+ }
484
+ }
485
+ else {
486
+ if (startPart === 0 && isAbsolute) {
487
+ ret.name = path.slice(1, startDot);
488
+ ret.base = path.slice(1, end);
489
+ }
490
+ else {
491
+ ret.name = path.slice(startPart, startDot);
492
+ ret.base = path.slice(startPart, end);
493
+ }
494
+ ret.ext = path.slice(startDot, end);
495
+ }
496
+ if (startPart > 0)
497
+ ret.dir = path.slice(0, startPart - 1);
498
+ else if (isAbsolute)
499
+ ret.dir = "/";
500
+ return ret;
501
+ }
502
+ exports.parse = parse;
503
+ /**
504
+ * Converts a file URL to a path string.
505
+ *
506
+ * ```ts
507
+ * import { fromFileUrl } from "./posix.ts";
508
+ * fromFileUrl("file:///home/foo"); // "/home/foo"
509
+ * ```
510
+ * @param url of a file URL
511
+ */
512
+ function fromFileUrl(url) {
513
+ url = url instanceof URL ? url : new URL(url);
514
+ if (url.protocol != "file:") {
515
+ throw new TypeError("Must be a file URL.");
516
+ }
517
+ return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"));
518
+ }
519
+ exports.fromFileUrl = fromFileUrl;
520
+ /**
521
+ * Converts a path string to a file URL.
522
+ *
523
+ * ```ts
524
+ * import { toFileUrl } from "./posix.ts";
525
+ * toFileUrl("/home/foo"); // new URL("file:///home/foo")
526
+ * ```
527
+ * @param path to convert to file URL
528
+ */
529
+ function toFileUrl(path) {
530
+ if (!isAbsolute(path)) {
531
+ throw new TypeError("Must be an absolute path.");
532
+ }
533
+ const url = new URL("file:///");
534
+ url.pathname = (0, _util_js_1.encodeWhitespace)(path.replace(/%/g, "%25").replace(/\\/g, "%5C"));
535
+ return url;
536
+ }
537
+ exports.toFileUrl = toFileUrl;
538
+ });
@@ -0,0 +1,18 @@
1
+ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ (function (factory) {
4
+ if (typeof module === "object" && typeof module.exports === "object") {
5
+ var v = factory(require, exports);
6
+ if (v !== undefined) module.exports = v;
7
+ }
8
+ else if (typeof define === "function" && define.amd) {
9
+ define(["require", "exports", "../_util/os.js"], factory);
10
+ }
11
+ })(function (require, exports) {
12
+ "use strict";
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.SEP_PATTERN = exports.SEP = void 0;
15
+ const os_js_1 = require("../_util/os.js");
16
+ exports.SEP = os_js_1.isWindows ? "\\" : "/";
17
+ exports.SEP_PATTERN = os_js_1.isWindows ? /[\\/]+/ : /\/+/;
18
+ });