keep-a-changelog 2.1.0 → 2.3.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 (128) hide show
  1. package/CHANGELOG.md +28 -2
  2. package/README.md +23 -6
  3. package/esm/_dnt.test_shims.d.ts +5 -0
  4. package/esm/bin.js +11 -2
  5. package/esm/deps/deno.land/std@0.133.0/fmt/colors.d.ts +270 -0
  6. package/esm/deps/deno.land/std@0.133.0/testing/_diff.d.ts +23 -0
  7. package/esm/deps/deno.land/std@0.133.0/testing/asserts.d.ts +167 -0
  8. package/esm/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
  9. package/esm/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +227 -334
  10. package/esm/deps/deno.land/std@0.189.0/_util/asserts.d.ts +10 -0
  11. package/esm/deps/deno.land/std@0.189.0/_util/asserts.js +21 -0
  12. package/esm/deps/deno.land/std@0.189.0/_util/os.d.ts +4 -0
  13. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/_util/os.js +3 -2
  14. package/esm/deps/deno.land/std@0.189.0/flags/mod.d.ts +166 -0
  15. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/flags/mod.js +146 -36
  16. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_constants.js +1 -0
  17. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_interface.d.ts +1 -1
  18. package/esm/deps/deno.land/std@0.189.0/path/_interface.js +3 -0
  19. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_util.d.ts +3 -0
  20. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_util.js +47 -0
  21. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/common.js +1 -1
  22. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/glob.d.ts +10 -5
  23. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/glob.js +1 -1
  24. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/mod.d.ts +3 -1
  25. package/esm/deps/deno.land/std@0.189.0/path/mod.js +35 -0
  26. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/posix.d.ts +15 -9
  27. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/posix.js +58 -112
  28. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/separator.js +1 -1
  29. package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/win32.d.ts +13 -9
  30. package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/win32.js +30 -87
  31. package/esm/src/Change.js +15 -15
  32. package/{types → esm}/src/Changelog.d.ts +1 -0
  33. package/esm/src/Changelog.js +9 -1
  34. package/{types → esm}/src/Release.d.ts +1 -0
  35. package/esm/src/Release.js +10 -0
  36. package/esm/src/deps.d.ts +1 -0
  37. package/esm/src/deps.js +1 -1
  38. package/esm/src/parser.js +19 -3
  39. package/esm/test/Change.test.d.ts +1 -0
  40. package/esm/test/changelog.custom.type.md +0 -1
  41. package/esm/test/changelog.expected.linted.md +208 -0
  42. package/esm/test/changelog.expected.md +3 -1
  43. package/esm/test/changelog.md +4 -0
  44. package/esm/test/deps.d.ts +1 -0
  45. package/esm/test/empty.expected.md +0 -1
  46. package/esm/test/fixture/CustomRelease.d.ts +8 -0
  47. package/esm/test/parser.test.d.ts +1 -0
  48. package/esm/test/test.d.ts +1 -0
  49. package/package.json +6 -8
  50. package/script/_dnt.polyfills.d.ts +11 -0
  51. package/script/_dnt.shims.d.ts +5 -0
  52. package/script/_dnt.test_shims.d.ts +5 -0
  53. package/script/bin.d.ts +2 -0
  54. package/script/bin.js +11 -2
  55. package/script/deps/deno.land/std@0.133.0/fmt/colors.d.ts +270 -0
  56. package/script/deps/deno.land/std@0.133.0/testing/_diff.d.ts +23 -0
  57. package/script/deps/deno.land/std@0.133.0/testing/asserts.d.ts +167 -0
  58. package/script/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
  59. package/script/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +232 -342
  60. package/script/deps/deno.land/std@0.189.0/_util/asserts.d.ts +10 -0
  61. package/script/deps/deno.land/std@0.189.0/_util/asserts.js +27 -0
  62. package/script/deps/deno.land/std@0.189.0/_util/os.d.ts +4 -0
  63. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/_util/os.js +4 -3
  64. package/script/deps/deno.land/std@0.189.0/flags/mod.d.ts +166 -0
  65. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/flags/mod.js +150 -40
  66. package/script/deps/deno.land/std@0.189.0/path/_constants.d.ts +39 -0
  67. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_constants.js +1 -0
  68. package/script/deps/deno.land/std@0.189.0/path/_interface.d.ts +26 -0
  69. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_interface.js +1 -1
  70. package/script/deps/deno.land/std@0.189.0/path/_util.d.ts +11 -0
  71. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_util.js +51 -1
  72. package/script/deps/deno.land/std@0.189.0/path/common.d.ts +13 -0
  73. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/common.js +1 -1
  74. package/script/deps/deno.land/std@0.189.0/path/glob.d.ts +83 -0
  75. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/glob.js +1 -1
  76. package/script/deps/deno.land/std@0.189.0/path/mod.d.ts +11 -0
  77. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/mod.js +23 -2
  78. package/script/deps/deno.land/std@0.189.0/path/posix.d.ts +86 -0
  79. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/posix.js +56 -110
  80. package/script/deps/deno.land/std@0.189.0/path/separator.d.ts +2 -0
  81. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/separator.js +1 -1
  82. package/script/deps/deno.land/std@0.189.0/path/win32.d.ts +91 -0
  83. package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/win32.js +30 -87
  84. package/script/deps/deno.land/std@0.51.0/fs/eol.d.ts +12 -0
  85. package/script/deps/deno.land/x/ini@v2.1.0/ini.d.ts +53 -0
  86. package/script/deps/deno.land/x/ini@v2.1.0/mod.d.ts +1 -0
  87. package/script/mod.d.ts +6 -0
  88. package/script/src/Change.d.ts +8 -0
  89. package/script/src/Change.js +15 -15
  90. package/script/src/Changelog.d.ts +19 -0
  91. package/script/src/Changelog.js +9 -1
  92. package/script/src/Release.d.ts +27 -0
  93. package/script/src/Release.js +10 -0
  94. package/script/src/deps.d.ts +1 -0
  95. package/script/src/deps.js +1 -1
  96. package/script/src/parser.d.ts +11 -0
  97. package/script/src/parser.js +19 -3
  98. package/script/test/Change.test.d.ts +1 -0
  99. package/script/test/changelog.custom.type.md +0 -1
  100. package/script/test/changelog.expected.linted.md +208 -0
  101. package/script/test/changelog.expected.md +3 -1
  102. package/script/test/changelog.md +4 -0
  103. package/script/test/deps.d.ts +1 -0
  104. package/script/test/empty.expected.md +0 -1
  105. package/script/test/fixture/CustomRelease.d.ts +8 -0
  106. package/script/test/parser.test.d.ts +1 -0
  107. package/script/test/test.d.ts +1 -0
  108. package/esm/deps/deno.land/std@0.120.0/_util/assert.js +0 -13
  109. package/esm/deps/deno.land/std@0.120.0/path/_interface.js +0 -3
  110. package/esm/deps/deno.land/std@0.120.0/path/mod.js +0 -14
  111. package/script/deps/deno.land/std@0.120.0/_util/assert.js +0 -18
  112. package/types/deps/deno.land/std@0.120.0/_util/assert.d.ts +0 -5
  113. package/types/deps/deno.land/std@0.120.0/_util/os.d.ts +0 -3
  114. package/types/deps/deno.land/std@0.120.0/flags/mod.d.ts +0 -50
  115. package/types/deps/deno.land/x/semver@v1.4.0/mod.d.ts +0 -116
  116. package/types/src/deps.d.ts +0 -1
  117. /package/{types → esm}/_dnt.polyfills.d.ts +0 -0
  118. /package/{types → esm}/_dnt.shims.d.ts +0 -0
  119. /package/{types → esm}/bin.d.ts +0 -0
  120. /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_constants.d.ts +0 -0
  121. /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/common.d.ts +0 -0
  122. /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/separator.d.ts +0 -0
  123. /package/{types → esm}/deps/deno.land/std@0.51.0/fs/eol.d.ts +0 -0
  124. /package/{types → esm}/deps/deno.land/x/ini@v2.1.0/ini.d.ts +0 -0
  125. /package/{types → esm}/deps/deno.land/x/ini@v2.1.0/mod.d.ts +0 -0
  126. /package/{types → esm}/mod.d.ts +0 -0
  127. /package/{types → esm}/src/Change.d.ts +0 -0
  128. /package/{types → esm}/src/parser.d.ts +0 -0
@@ -0,0 +1,35 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright the Browserify authors. MIT License.
3
+ // Ported mostly from https://github.com/browserify/path-browserify/
4
+ // This module is browser compatible.
5
+ /**
6
+ * Utilities for working with OS-specific file paths.
7
+ *
8
+ * Codes in the examples uses POSIX path but it automatically use Windows path
9
+ * on Windows. Use methods under `posix` or `win32` object instead to handle non
10
+ * platform specific path like:
11
+ * ```ts
12
+ * import { posix, win32 } from "https://deno.land/std@$STD_VERSION/path/mod.ts";
13
+ * const p1 = posix.fromFileUrl("file:///home/foo");
14
+ * const p2 = win32.fromFileUrl("file:///home/foo");
15
+ * console.log(p1); // "/home/foo"
16
+ * console.log(p2); // "\\home\\foo"
17
+ * ```
18
+ *
19
+ * This module is browser compatible.
20
+ *
21
+ * @module
22
+ */
23
+ import { isWindows } from "../_util/os.js";
24
+ import * as _win32 from "./win32.js";
25
+ import * as _posix from "./posix.js";
26
+ const path = isWindows ? _win32 : _posix;
27
+ export const win32 = _win32;
28
+ export const posix = _posix;
29
+ export const { basename, delimiter, dirname, extname, format, fromFileUrl, isAbsolute, join, normalize, parse, relative, resolve, toFileUrl, toNamespacedPath, } = path;
30
+ /** @deprecated (will be removed after 0.188.0) Use SEP intead. */
31
+ export const sep = path.sep;
32
+ export * from "./common.js";
33
+ export { SEP, SEP_PATTERN } from "./separator.js";
34
+ export * from "./_interface.js";
35
+ export * from "./glob.js";
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { FormatInputPathObject, ParsedPath } from "./_interface.js";
2
3
  export declare const sep = "/";
3
4
  export declare const delimiter = ":";
@@ -8,6 +9,8 @@ export declare const delimiter = ":";
8
9
  export declare function resolve(...pathSegments: string[]): string;
9
10
  /**
10
11
  * Normalize the `path`, resolving `'..'` and `'.'` segments.
12
+ * Note that resolving these segments does not necessarily mean that all will be eliminated.
13
+ * A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
11
14
  * @param path to be normalized
12
15
  */
13
16
  export declare function normalize(path: string): string;
@@ -33,19 +36,22 @@ export declare function relative(from: string, to: string): string;
33
36
  */
34
37
  export declare function toNamespacedPath(path: string): string;
35
38
  /**
36
- * Return the directory name of a `path`.
37
- * @param path to determine name for
39
+ * Return the directory path of a `path`.
40
+ * @param path - path to extract the directory from.
38
41
  */
39
42
  export declare function dirname(path: string): string;
40
43
  /**
41
- * Return the last portion of a `path`. Trailing directory separators are ignored.
42
- * @param path to process
43
- * @param ext of path directory
44
+ * Return the last portion of a `path`.
45
+ * Trailing directory separators are ignored, and optional suffix is removed.
46
+ *
47
+ * @param path - path to extract the name from.
48
+ * @param [suffix] - suffix to remove from extracted name.
44
49
  */
45
- export declare function basename(path: string, ext?: string): string;
50
+ export declare function basename(path: string, suffix?: string): string;
46
51
  /**
47
- * Return the extension of the `path`.
52
+ * Return the extension of the `path` with leading period.
48
53
  * @param path with extension
54
+ * @returns extension (ex. for `file.ts` returns `.ts`)
49
55
  */
50
56
  export declare function extname(path: string): string;
51
57
  /**
@@ -62,7 +68,7 @@ export declare function parse(path: string): ParsedPath;
62
68
  * Converts a file URL to a path string.
63
69
  *
64
70
  * ```ts
65
- * import { fromFileUrl } from "./posix.ts";
71
+ * import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
66
72
  * fromFileUrl("file:///home/foo"); // "/home/foo"
67
73
  * ```
68
74
  * @param url of a file URL
@@ -72,7 +78,7 @@ export declare function fromFileUrl(url: string | URL): string;
72
78
  * Converts a path string to a file URL.
73
79
  *
74
80
  * ```ts
75
- * import { toFileUrl } from "./posix.ts";
81
+ * import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
76
82
  * toFileUrl("/home/foo"); // new URL("file:///home/foo")
77
83
  * ```
78
84
  * @param path to convert to file URL
@@ -1,9 +1,10 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
1
2
  // Copyright the Browserify authors. MIT License.
2
3
  // Ported from https://github.com/browserify/path-browserify/
3
4
  // This module is browser compatible.
4
5
  import * as dntShim from "../../../../_dnt.shims.js";
5
- import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./_constants.js";
6
- import { _format, assertPath, encodeWhitespace, isPosixPathSeparator, normalizeString, } from "./_util.js";
6
+ import { CHAR_DOT } from "./_constants.js";
7
+ import { _format, assertPath, encodeWhitespace, isPosixPathSeparator, lastPathSegment, normalizeString, stripSuffix, stripTrailingSeparators, } from "./_util.js";
7
8
  export const sep = "/";
8
9
  export const delimiter = ":";
9
10
  // path.resolve([from ...], to)
@@ -32,7 +33,7 @@ export function resolve(...pathSegments) {
32
33
  continue;
33
34
  }
34
35
  resolvedPath = `${path}/${resolvedPath}`;
35
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
36
+ resolvedAbsolute = isPosixPathSeparator(path.charCodeAt(0));
36
37
  }
37
38
  // At this point the path should be resolved to a full absolute path, but
38
39
  // handle relative paths to be safe (might happen when process.cwd() fails)
@@ -51,14 +52,16 @@ export function resolve(...pathSegments) {
51
52
  }
52
53
  /**
53
54
  * Normalize the `path`, resolving `'..'` and `'.'` segments.
55
+ * Note that resolving these segments does not necessarily mean that all will be eliminated.
56
+ * A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
54
57
  * @param path to be normalized
55
58
  */
56
59
  export function normalize(path) {
57
60
  assertPath(path);
58
61
  if (path.length === 0)
59
62
  return ".";
60
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
61
- const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
63
+ const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
64
+ const trailingSeparator = isPosixPathSeparator(path.charCodeAt(path.length - 1));
62
65
  // Normalize the path
63
66
  path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
64
67
  if (path.length === 0 && !isAbsolute)
@@ -75,7 +78,7 @@ export function normalize(path) {
75
78
  */
76
79
  export function isAbsolute(path) {
77
80
  assertPath(path);
78
- return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
81
+ return path.length > 0 && isPosixPathSeparator(path.charCodeAt(0));
79
82
  }
80
83
  /**
81
84
  * Join all given a sequence of `paths`,then normalizes the resulting path.
@@ -117,7 +120,7 @@ export function relative(from, to) {
117
120
  let fromStart = 1;
118
121
  const fromEnd = from.length;
119
122
  for (; fromStart < fromEnd; ++fromStart) {
120
- if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH)
123
+ if (!isPosixPathSeparator(from.charCodeAt(fromStart)))
121
124
  break;
122
125
  }
123
126
  const fromLen = fromEnd - fromStart;
@@ -125,7 +128,7 @@ export function relative(from, to) {
125
128
  let toStart = 1;
126
129
  const toEnd = to.length;
127
130
  for (; toStart < toEnd; ++toStart) {
128
- if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH)
131
+ if (!isPosixPathSeparator(to.charCodeAt(toStart)))
129
132
  break;
130
133
  }
131
134
  const toLen = toEnd - toStart;
@@ -136,7 +139,7 @@ export function relative(from, to) {
136
139
  for (; i <= length; ++i) {
137
140
  if (i === length) {
138
141
  if (toLen > length) {
139
- if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
142
+ if (isPosixPathSeparator(to.charCodeAt(toStart + i))) {
140
143
  // We get here if `from` is the exact base path for `to`.
141
144
  // For example: from='/foo/bar'; to='/foo/bar/baz'
142
145
  return to.slice(toStart + i + 1);
@@ -148,7 +151,7 @@ export function relative(from, to) {
148
151
  }
149
152
  }
150
153
  else if (fromLen > length) {
151
- if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
154
+ if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) {
152
155
  // We get here if `to` is the exact base path for `from`.
153
156
  // For example: from='/foo/bar/baz'; to='/foo/bar'
154
157
  lastCommonSep = i;
@@ -165,14 +168,14 @@ export function relative(from, to) {
165
168
  const toCode = to.charCodeAt(toStart + i);
166
169
  if (fromCode !== toCode)
167
170
  break;
168
- else if (fromCode === CHAR_FORWARD_SLASH)
171
+ else if (isPosixPathSeparator(fromCode))
169
172
  lastCommonSep = i;
170
173
  }
171
174
  let out = "";
172
175
  // Generate the relative path based on the path difference between `to`
173
176
  // and `from`
174
177
  for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
175
- if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
178
+ if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) {
176
179
  if (out.length === 0)
177
180
  out += "..";
178
181
  else
@@ -185,7 +188,7 @@ export function relative(from, to) {
185
188
  return out + to.slice(toStart + lastCommonSep);
186
189
  else {
187
190
  toStart += lastCommonSep;
188
- if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH)
191
+ if (isPosixPathSeparator(to.charCodeAt(toStart)))
189
192
  ++toStart;
190
193
  return to.slice(toStart);
191
194
  }
@@ -199,119 +202,59 @@ export function toNamespacedPath(path) {
199
202
  return path;
200
203
  }
201
204
  /**
202
- * Return the directory name of a `path`.
203
- * @param path to determine name for
205
+ * Return the directory path of a `path`.
206
+ * @param path - path to extract the directory from.
204
207
  */
205
208
  export function dirname(path) {
206
- assertPath(path);
207
209
  if (path.length === 0)
208
210
  return ".";
209
- const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
210
211
  let end = -1;
211
- let matchedSlash = true;
212
+ let matchedNonSeparator = false;
212
213
  for (let i = path.length - 1; i >= 1; --i) {
213
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
214
- if (!matchedSlash) {
214
+ if (isPosixPathSeparator(path.charCodeAt(i))) {
215
+ if (matchedNonSeparator) {
215
216
  end = i;
216
217
  break;
217
218
  }
218
219
  }
219
220
  else {
220
- // We saw the first non-path separator
221
- matchedSlash = false;
221
+ matchedNonSeparator = true;
222
222
  }
223
223
  }
224
- if (end === -1)
225
- return hasRoot ? "/" : ".";
226
- if (hasRoot && end === 1)
227
- return "//";
228
- return path.slice(0, end);
224
+ // No matches. Fallback based on provided path:
225
+ //
226
+ // - leading slashes paths
227
+ // "/foo" => "/"
228
+ // "///foo" => "/"
229
+ // - no slash path
230
+ // "foo" => "."
231
+ if (end === -1) {
232
+ return isPosixPathSeparator(path.charCodeAt(0)) ? "/" : ".";
233
+ }
234
+ return stripTrailingSeparators(path.slice(0, end), isPosixPathSeparator);
229
235
  }
230
236
  /**
231
- * Return the last portion of a `path`. Trailing directory separators are ignored.
232
- * @param path to process
233
- * @param ext of path directory
237
+ * Return the last portion of a `path`.
238
+ * Trailing directory separators are ignored, and optional suffix is removed.
239
+ *
240
+ * @param path - path to extract the name from.
241
+ * @param [suffix] - suffix to remove from extracted name.
234
242
  */
235
- export function basename(path, ext = "") {
236
- if (ext !== undefined && typeof ext !== "string") {
237
- throw new TypeError('"ext" argument must be a string');
238
- }
243
+ export function basename(path, suffix = "") {
239
244
  assertPath(path);
240
- let start = 0;
241
- let end = -1;
242
- let matchedSlash = true;
243
- let i;
244
- if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
245
- if (ext.length === path.length && ext === path)
246
- return "";
247
- let extIdx = ext.length - 1;
248
- let firstNonSlashEnd = -1;
249
- for (i = path.length - 1; i >= 0; --i) {
250
- const code = path.charCodeAt(i);
251
- if (code === CHAR_FORWARD_SLASH) {
252
- // If we reached a path separator that was not part of a set of path
253
- // separators at the end of the string, stop now
254
- if (!matchedSlash) {
255
- start = i + 1;
256
- break;
257
- }
258
- }
259
- else {
260
- if (firstNonSlashEnd === -1) {
261
- // We saw the first non-path separator, remember this index in case
262
- // we need it if the extension ends up not matching
263
- matchedSlash = false;
264
- firstNonSlashEnd = i + 1;
265
- }
266
- if (extIdx >= 0) {
267
- // Try to match the explicit extension
268
- if (code === ext.charCodeAt(extIdx)) {
269
- if (--extIdx === -1) {
270
- // We matched the extension, so mark this as the end of our path
271
- // component
272
- end = i;
273
- }
274
- }
275
- else {
276
- // Extension does not match, so our result is the entire path
277
- // component
278
- extIdx = -1;
279
- end = firstNonSlashEnd;
280
- }
281
- }
282
- }
283
- }
284
- if (start === end)
285
- end = firstNonSlashEnd;
286
- else if (end === -1)
287
- end = path.length;
288
- return path.slice(start, end);
289
- }
290
- else {
291
- for (i = path.length - 1; i >= 0; --i) {
292
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
293
- // If we reached a path separator that was not part of a set of path
294
- // separators at the end of the string, stop now
295
- if (!matchedSlash) {
296
- start = i + 1;
297
- break;
298
- }
299
- }
300
- else if (end === -1) {
301
- // We saw the first non-path separator, mark this as the end of our
302
- // path component
303
- matchedSlash = false;
304
- end = i + 1;
305
- }
306
- }
307
- if (end === -1)
308
- return "";
309
- return path.slice(start, end);
245
+ if (path.length === 0)
246
+ return path;
247
+ if (typeof suffix !== "string") {
248
+ throw new TypeError(`Suffix must be a string. Received ${JSON.stringify(suffix)}`);
310
249
  }
250
+ const lastSegment = lastPathSegment(path, isPosixPathSeparator);
251
+ const strippedSegment = stripTrailingSeparators(lastSegment, isPosixPathSeparator);
252
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
311
253
  }
312
254
  /**
313
- * Return the extension of the `path`.
255
+ * Return the extension of the `path` with leading period.
314
256
  * @param path with extension
257
+ * @returns extension (ex. for `file.ts` returns `.ts`)
315
258
  */
316
259
  export function extname(path) {
317
260
  assertPath(path);
@@ -324,7 +267,7 @@ export function extname(path) {
324
267
  let preDotState = 0;
325
268
  for (let i = path.length - 1; i >= 0; --i) {
326
269
  const code = path.charCodeAt(i);
327
- if (code === CHAR_FORWARD_SLASH) {
270
+ if (isPosixPathSeparator(code)) {
328
271
  // If we reached a path separator that was not part of a set of path
329
272
  // separators at the end of the string, stop now
330
273
  if (!matchedSlash) {
@@ -381,7 +324,7 @@ export function parse(path) {
381
324
  const ret = { root: "", dir: "", base: "", ext: "", name: "" };
382
325
  if (path.length === 0)
383
326
  return ret;
384
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
327
+ const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
385
328
  let start;
386
329
  if (isAbsolute) {
387
330
  ret.root = "/";
@@ -401,7 +344,7 @@ export function parse(path) {
401
344
  // Get non-dir info
402
345
  for (; i >= start; --i) {
403
346
  const code = path.charCodeAt(i);
404
- if (code === CHAR_FORWARD_SLASH) {
347
+ if (isPosixPathSeparator(code)) {
405
348
  // If we reached a path separator that was not part of a set of path
406
349
  // separators at the end of the string, stop now
407
350
  if (!matchedSlash) {
@@ -443,6 +386,8 @@ export function parse(path) {
443
386
  ret.base = ret.name = path.slice(startPart, end);
444
387
  }
445
388
  }
389
+ // Fallback to '/' in case there is no basename
390
+ ret.base = ret.base || "/";
446
391
  }
447
392
  else {
448
393
  if (startPart === 0 && isAbsolute) {
@@ -455,8 +400,9 @@ export function parse(path) {
455
400
  }
456
401
  ret.ext = path.slice(startDot, end);
457
402
  }
458
- if (startPart > 0)
459
- ret.dir = path.slice(0, startPart - 1);
403
+ if (startPart > 0) {
404
+ ret.dir = stripTrailingSeparators(path.slice(0, startPart - 1), isPosixPathSeparator);
405
+ }
460
406
  else if (isAbsolute)
461
407
  ret.dir = "/";
462
408
  return ret;
@@ -465,7 +411,7 @@ export function parse(path) {
465
411
  * Converts a file URL to a path string.
466
412
  *
467
413
  * ```ts
468
- * import { fromFileUrl } from "./posix.ts";
414
+ * import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
469
415
  * fromFileUrl("file:///home/foo"); // "/home/foo"
470
416
  * ```
471
417
  * @param url of a file URL
@@ -481,7 +427,7 @@ export function fromFileUrl(url) {
481
427
  * Converts a path string to a file URL.
482
428
  *
483
429
  * ```ts
484
- * import { toFileUrl } from "./posix.ts";
430
+ * import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
485
431
  * toFileUrl("/home/foo"); // new URL("file:///home/foo")
486
432
  * ```
487
433
  * @param path to convert to file URL
@@ -1,4 +1,4 @@
1
- // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
2
  // This module is browser compatible.
3
3
  import { isWindows } from "../_util/os.js";
4
4
  export const SEP = isWindows ? "\\" : "/";
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { FormatInputPathObject, ParsedPath } from "./_interface.js";
2
3
  export declare const sep = "\\";
3
4
  export declare const delimiter = ";";
@@ -36,19 +37,22 @@ export declare function relative(from: string, to: string): string;
36
37
  */
37
38
  export declare function toNamespacedPath(path: string): string;
38
39
  /**
39
- * Return the directory name of a `path`.
40
- * @param path to determine name for
40
+ * Return the directory path of a `path`.
41
+ * @param path - path to extract the directory from.
41
42
  */
42
43
  export declare function dirname(path: string): string;
43
44
  /**
44
- * Return the last portion of a `path`. Trailing directory separators are ignored.
45
- * @param path to process
46
- * @param ext of path directory
45
+ * Return the last portion of a `path`.
46
+ * Trailing directory separators are ignored, and optional suffix is removed.
47
+ *
48
+ * @param path - path to extract name from.
49
+ * @param [suffix] - suffix to remove from extracted name.
47
50
  */
48
- export declare function basename(path: string, ext?: string): string;
51
+ export declare function basename(path: string, suffix?: string): string;
49
52
  /**
50
- * Return the extension of the `path`.
53
+ * Return the extension of the `path` with leading period.
51
54
  * @param path with extension
55
+ * @returns extension (ex. for `file.ts` returns `.ts`)
52
56
  */
53
57
  export declare function extname(path: string): string;
54
58
  /**
@@ -65,7 +69,7 @@ export declare function parse(path: string): ParsedPath;
65
69
  * Converts a file URL to a path string.
66
70
  *
67
71
  * ```ts
68
- * import { fromFileUrl } from "./win32.ts";
72
+ * import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
69
73
  * fromFileUrl("file:///home/foo"); // "\\home\\foo"
70
74
  * fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
71
75
  * fromFileUrl("file://localhost/home/foo"); // "\\\\localhost\\home\\foo"
@@ -77,7 +81,7 @@ export declare function fromFileUrl(url: string | URL): string;
77
81
  * Converts a path string to a file URL.
78
82
  *
79
83
  * ```ts
80
- * import { toFileUrl } from "./win32.ts";
84
+ * import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
81
85
  * toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
82
86
  * toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
83
87
  * toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")