keep-a-changelog 2.0.1 → 2.1.0

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