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