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