keep-a-changelog 0.10.4 → 2.0.0-beta

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 (96) hide show
  1. package/CHANGELOG.md +5 -196
  2. package/LICENSE +1 -1
  3. package/README.md +93 -63
  4. package/esm/bin.js +113 -0
  5. package/esm/deps/deno_land/std_0.113.0/_util/assert.js +13 -0
  6. package/esm/deps/deno_land/std_0.113.0/_util/os.js +15 -0
  7. package/esm/deps/deno_land/std_0.113.0/flags/mod.js +255 -0
  8. package/esm/deps/deno_land/std_0.113.0/path/_constants.js +45 -0
  9. package/esm/deps/deno_land/std_0.113.0/path/_interface.js +3 -0
  10. package/esm/deps/deno_land/std_0.113.0/path/_util.js +114 -0
  11. package/esm/deps/deno_land/std_0.113.0/path/common.js +36 -0
  12. package/esm/deps/deno_land/std_0.113.0/path/glob.js +361 -0
  13. package/esm/deps/deno_land/std_0.113.0/path/mod.js +14 -0
  14. package/esm/deps/deno_land/std_0.113.0/path/posix.js +493 -0
  15. package/esm/deps/deno_land/std_0.113.0/path/separator.js +5 -0
  16. package/esm/deps/deno_land/std_0.113.0/path/win32.js +963 -0
  17. package/esm/deps/deno_land/std_0.51.0/fs/eol.js +29 -0
  18. package/esm/deps/deno_land/x/ini_v2.1.0/ini.js +226 -0
  19. package/esm/deps/deno_land/x/ini_v2.1.0/mod.js +1 -0
  20. package/esm/deps/deno_land/x/semver_v1.4.0/mod.js +1527 -0
  21. package/esm/mod.js +5 -0
  22. package/esm/package.json +3 -0
  23. package/esm/src/Change.js +48 -0
  24. package/esm/src/Changelog.js +137 -0
  25. package/esm/src/Release.js +204 -0
  26. package/esm/src/deps.js +1 -0
  27. package/esm/src/parser.js +149 -0
  28. package/esm/test/changelog.custom.type.md +24 -0
  29. package/esm/test/changelog.expected.md +169 -0
  30. package/esm/test/changelog.md +197 -0
  31. package/esm/test/empty.expected.md +6 -0
  32. package/package.json +26 -24
  33. package/types/bin.d.ts +2 -0
  34. package/types/deps/deno_land/std_0.113.0/_util/assert.d.ts +5 -0
  35. package/types/deps/deno_land/std_0.113.0/_util/os.d.ts +3 -0
  36. package/types/deps/deno_land/std_0.113.0/flags/mod.d.ts +50 -0
  37. package/types/deps/deno_land/std_0.113.0/path/_constants.d.ts +39 -0
  38. package/types/deps/deno_land/std_0.113.0/path/_interface.d.ts +26 -0
  39. package/types/deps/deno_land/std_0.113.0/path/_util.d.ts +8 -0
  40. package/types/deps/deno_land/std_0.113.0/path/common.d.ts +13 -0
  41. package/types/deps/deno_land/std_0.113.0/path/glob.d.ts +78 -0
  42. package/types/deps/deno_land/std_0.113.0/path/mod.d.ts +9 -0
  43. package/types/deps/deno_land/std_0.113.0/path/posix.d.ts +80 -0
  44. package/types/deps/deno_land/std_0.113.0/path/separator.d.ts +2 -0
  45. package/types/deps/deno_land/std_0.113.0/path/win32.d.ts +87 -0
  46. package/types/deps/deno_land/std_0.115.1/fmt/colors.d.ts +270 -0
  47. package/types/deps/deno_land/std_0.115.1/testing/_diff.d.ts +23 -0
  48. package/types/deps/deno_land/std_0.115.1/testing/asserts.d.ts +151 -0
  49. package/types/deps/deno_land/std_0.51.0/fs/eol.d.ts +12 -0
  50. package/types/deps/deno_land/x/ini_v2.1.0/ini.d.ts +53 -0
  51. package/types/deps/deno_land/x/ini_v2.1.0/mod.d.ts +1 -0
  52. package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +116 -0
  53. package/types/mod.d.ts +5 -0
  54. package/types/src/Change.d.ts +8 -0
  55. package/types/src/Changelog.d.ts +18 -0
  56. package/types/src/Release.d.ts +25 -0
  57. package/types/src/deps.d.ts +1 -0
  58. package/types/src/parser.d.ts +11 -0
  59. package/types/test/Change.test.d.ts +1 -0
  60. package/types/test/fixture/CustomRelease.d.ts +7 -0
  61. package/types/test/parser.test.d.ts +1 -0
  62. package/types/test/test.d.ts +1 -0
  63. package/umd/bin.js +143 -0
  64. package/umd/deps/deno_land/std_0.113.0/_util/assert.js +27 -0
  65. package/umd/deps/deno_land/std_0.113.0/_util/os.js +46 -0
  66. package/umd/deps/deno_land/std_0.113.0/flags/mod.js +268 -0
  67. package/umd/deps/deno_land/std_0.113.0/path/_constants.js +57 -0
  68. package/umd/deps/deno_land/std_0.113.0/path/_interface.js +13 -0
  69. package/umd/deps/deno_land/std_0.113.0/path/_util.js +133 -0
  70. package/umd/deps/deno_land/std_0.113.0/path/common.js +49 -0
  71. package/umd/deps/deno_land/std_0.113.0/path/glob.js +396 -0
  72. package/umd/deps/deno_land/std_0.113.0/path/mod.js +50 -0
  73. package/umd/deps/deno_land/std_0.113.0/path/posix.js +537 -0
  74. package/umd/deps/deno_land/std_0.113.0/path/separator.js +17 -0
  75. package/umd/deps/deno_land/std_0.113.0/path/win32.js +1007 -0
  76. package/umd/deps/deno_land/std_0.51.0/fs/eol.js +43 -0
  77. package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +261 -0
  78. package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +22 -0
  79. package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +1577 -0
  80. package/umd/mod.js +23 -0
  81. package/umd/package.json +3 -0
  82. package/umd/src/Change.js +60 -0
  83. package/umd/src/Changelog.js +149 -0
  84. package/umd/src/Release.js +219 -0
  85. package/umd/src/deps.js +18 -0
  86. package/umd/src/parser.js +164 -0
  87. package/umd/test/changelog.custom.type.md +24 -0
  88. package/umd/test/changelog.expected.md +169 -0
  89. package/umd/test/changelog.md +197 -0
  90. package/umd/test/empty.expected.md +6 -0
  91. package/bin.js +0 -128
  92. package/src/Change.js +0 -40
  93. package/src/Changelog.js +0 -121
  94. package/src/Release.js +0 -220
  95. package/src/index.js +0 -6
  96. package/src/parser.js +0 -182
@@ -0,0 +1,268 @@
1
+ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2
+ (function (factory) {
3
+ if (typeof module === "object" && typeof module.exports === "object") {
4
+ var v = factory(require, exports);
5
+ if (v !== undefined) module.exports = v;
6
+ }
7
+ else if (typeof define === "function" && define.amd) {
8
+ define(["require", "exports", "../_util/assert.js"], factory);
9
+ }
10
+ })(function (require, exports) {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.parse = void 0;
13
+ const assert_js_1 = require("../_util/assert.js");
14
+ const { hasOwn } = Object;
15
+ function get(obj, key) {
16
+ if (hasOwn(obj, key)) {
17
+ return obj[key];
18
+ }
19
+ }
20
+ function getForce(obj, key) {
21
+ const v = get(obj, key);
22
+ (0, assert_js_1.assert)(v != null);
23
+ return v;
24
+ }
25
+ function isNumber(x) {
26
+ if (typeof x === "number")
27
+ return true;
28
+ if (/^0x[0-9a-f]+$/i.test(String(x)))
29
+ return true;
30
+ return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(String(x));
31
+ }
32
+ function hasKey(obj, keys) {
33
+ let o = obj;
34
+ keys.slice(0, -1).forEach((key) => {
35
+ o = (get(o, key) ?? {});
36
+ });
37
+ const key = keys[keys.length - 1];
38
+ return key in o;
39
+ }
40
+ /** Take a set of command line arguments, with an optional set of options, and
41
+ * return an object representation of those argument.
42
+ *
43
+ * ```ts
44
+ * import { parse } from "./mod.ts";
45
+ * const parsedArgs = parse(Deno.args);
46
+ * ```
47
+ */
48
+ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
49
+ const flags = {
50
+ bools: {},
51
+ strings: {},
52
+ unknownFn: unknown,
53
+ allBools: false,
54
+ };
55
+ if (boolean !== undefined) {
56
+ if (typeof boolean === "boolean") {
57
+ flags.allBools = !!boolean;
58
+ }
59
+ else {
60
+ const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
61
+ for (const key of booleanArgs.filter(Boolean)) {
62
+ flags.bools[key] = true;
63
+ }
64
+ }
65
+ }
66
+ const aliases = {};
67
+ if (alias !== undefined) {
68
+ for (const key in alias) {
69
+ const val = getForce(alias, key);
70
+ if (typeof val === "string") {
71
+ aliases[key] = [val];
72
+ }
73
+ else {
74
+ aliases[key] = val;
75
+ }
76
+ for (const alias of getForce(aliases, key)) {
77
+ aliases[alias] = [key].concat(aliases[key].filter((y) => alias !== y));
78
+ }
79
+ }
80
+ }
81
+ if (string !== undefined) {
82
+ const stringArgs = typeof string === "string" ? [string] : string;
83
+ for (const key of stringArgs.filter(Boolean)) {
84
+ flags.strings[key] = true;
85
+ const alias = get(aliases, key);
86
+ if (alias) {
87
+ for (const al of alias) {
88
+ flags.strings[al] = true;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ const argv = { _: [] };
94
+ function argDefined(key, arg) {
95
+ return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
96
+ get(flags.bools, key) ||
97
+ !!get(flags.strings, key) ||
98
+ !!get(aliases, key));
99
+ }
100
+ function setKey(obj, keys, value) {
101
+ let o = obj;
102
+ keys.slice(0, -1).forEach(function (key) {
103
+ if (get(o, key) === undefined) {
104
+ o[key] = {};
105
+ }
106
+ o = get(o, key);
107
+ });
108
+ const key = keys[keys.length - 1];
109
+ if (get(o, key) === undefined ||
110
+ get(flags.bools, key) ||
111
+ typeof get(o, key) === "boolean") {
112
+ o[key] = value;
113
+ }
114
+ else if (Array.isArray(get(o, key))) {
115
+ o[key].push(value);
116
+ }
117
+ else {
118
+ o[key] = [get(o, key), value];
119
+ }
120
+ }
121
+ function setArg(key, val, arg = undefined) {
122
+ if (arg && flags.unknownFn && !argDefined(key, arg)) {
123
+ if (flags.unknownFn(arg, key, val) === false)
124
+ return;
125
+ }
126
+ const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
127
+ setKey(argv, key.split("."), value);
128
+ const alias = get(aliases, key);
129
+ if (alias) {
130
+ for (const x of alias) {
131
+ setKey(argv, x.split("."), value);
132
+ }
133
+ }
134
+ }
135
+ function aliasIsBoolean(key) {
136
+ return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
137
+ }
138
+ for (const key of Object.keys(flags.bools)) {
139
+ setArg(key, defaults[key] === undefined ? false : defaults[key]);
140
+ }
141
+ let notFlags = [];
142
+ // all args after "--" are not parsed
143
+ if (args.includes("--")) {
144
+ notFlags = args.slice(args.indexOf("--") + 1);
145
+ args = args.slice(0, args.indexOf("--"));
146
+ }
147
+ for (let i = 0; i < args.length; i++) {
148
+ const arg = args[i];
149
+ if (/^--.+=/.test(arg)) {
150
+ const m = arg.match(/^--([^=]+)=(.*)$/s);
151
+ (0, assert_js_1.assert)(m != null);
152
+ const [, key, value] = m;
153
+ if (flags.bools[key]) {
154
+ const booleanValue = value !== "false";
155
+ setArg(key, booleanValue, arg);
156
+ }
157
+ else {
158
+ setArg(key, value, arg);
159
+ }
160
+ }
161
+ else if (/^--no-.+/.test(arg)) {
162
+ const m = arg.match(/^--no-(.+)/);
163
+ (0, assert_js_1.assert)(m != null);
164
+ setArg(m[1], false, arg);
165
+ }
166
+ else if (/^--.+/.test(arg)) {
167
+ const m = arg.match(/^--(.+)/);
168
+ (0, assert_js_1.assert)(m != null);
169
+ const [, key] = m;
170
+ const next = args[i + 1];
171
+ if (next !== undefined &&
172
+ !/^-/.test(next) &&
173
+ !get(flags.bools, key) &&
174
+ !flags.allBools &&
175
+ (get(aliases, key) ? !aliasIsBoolean(key) : true)) {
176
+ setArg(key, next, arg);
177
+ i++;
178
+ }
179
+ else if (/^(true|false)$/.test(next)) {
180
+ setArg(key, next === "true", arg);
181
+ i++;
182
+ }
183
+ else {
184
+ setArg(key, get(flags.strings, key) ? "" : true, arg);
185
+ }
186
+ }
187
+ else if (/^-[^-]+/.test(arg)) {
188
+ const letters = arg.slice(1, -1).split("");
189
+ let broken = false;
190
+ for (let j = 0; j < letters.length; j++) {
191
+ const next = arg.slice(j + 2);
192
+ if (next === "-") {
193
+ setArg(letters[j], next, arg);
194
+ continue;
195
+ }
196
+ if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
197
+ setArg(letters[j], next.split(/=(.+)/)[1], arg);
198
+ broken = true;
199
+ break;
200
+ }
201
+ if (/[A-Za-z]/.test(letters[j]) &&
202
+ /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
203
+ setArg(letters[j], next, arg);
204
+ broken = true;
205
+ break;
206
+ }
207
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
208
+ setArg(letters[j], arg.slice(j + 2), arg);
209
+ broken = true;
210
+ break;
211
+ }
212
+ else {
213
+ setArg(letters[j], get(flags.strings, letters[j]) ? "" : true, arg);
214
+ }
215
+ }
216
+ const [key] = arg.slice(-1);
217
+ if (!broken && key !== "-") {
218
+ if (args[i + 1] &&
219
+ !/^(-|--)[^-]/.test(args[i + 1]) &&
220
+ !get(flags.bools, key) &&
221
+ (get(aliases, key) ? !aliasIsBoolean(key) : true)) {
222
+ setArg(key, args[i + 1], arg);
223
+ i++;
224
+ }
225
+ else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
226
+ setArg(key, args[i + 1] === "true", arg);
227
+ i++;
228
+ }
229
+ else {
230
+ setArg(key, get(flags.strings, key) ? "" : true, arg);
231
+ }
232
+ }
233
+ }
234
+ else {
235
+ if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
236
+ argv._.push(flags.strings["_"] ?? !isNumber(arg) ? arg : Number(arg));
237
+ }
238
+ if (stopEarly) {
239
+ argv._.push(...args.slice(i + 1));
240
+ break;
241
+ }
242
+ }
243
+ }
244
+ for (const key of Object.keys(defaults)) {
245
+ if (!hasKey(argv, key.split("."))) {
246
+ setKey(argv, key.split("."), defaults[key]);
247
+ if (aliases[key]) {
248
+ for (const x of aliases[key]) {
249
+ setKey(argv, x.split("."), defaults[key]);
250
+ }
251
+ }
252
+ }
253
+ }
254
+ if (doubleDash) {
255
+ argv["--"] = [];
256
+ for (const key of notFlags) {
257
+ argv["--"].push(key);
258
+ }
259
+ }
260
+ else {
261
+ for (const key of notFlags) {
262
+ argv._.push(key);
263
+ }
264
+ }
265
+ return argv;
266
+ }
267
+ exports.parse = parse;
268
+ });
@@ -0,0 +1,57 @@
1
+ // Copyright the Browserify authors. MIT License.
2
+ // Ported from https://github.com/browserify/path-browserify/
3
+ // This module is browser compatible.
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.CHAR_9 = exports.CHAR_0 = exports.CHAR_EQUAL = exports.CHAR_AMPERSAND = exports.CHAR_AT = exports.CHAR_GRAVE_ACCENT = exports.CHAR_CIRCUMFLEX_ACCENT = exports.CHAR_SEMICOLON = exports.CHAR_PERCENT = exports.CHAR_SINGLE_QUOTE = exports.CHAR_DOUBLE_QUOTE = exports.CHAR_PLUS = exports.CHAR_HYPHEN_MINUS = exports.CHAR_RIGHT_CURLY_BRACKET = exports.CHAR_LEFT_CURLY_BRACKET = exports.CHAR_RIGHT_ANGLE_BRACKET = exports.CHAR_LEFT_ANGLE_BRACKET = exports.CHAR_RIGHT_SQUARE_BRACKET = exports.CHAR_LEFT_SQUARE_BRACKET = exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = exports.CHAR_NO_BREAK_SPACE = exports.CHAR_SPACE = exports.CHAR_HASH = exports.CHAR_EXCLAMATION_MARK = exports.CHAR_FORM_FEED = exports.CHAR_TAB = exports.CHAR_CARRIAGE_RETURN = exports.CHAR_LINE_FEED = exports.CHAR_UNDERSCORE = exports.CHAR_QUESTION_MARK = exports.CHAR_COLON = exports.CHAR_VERTICAL_LINE = exports.CHAR_BACKWARD_SLASH = exports.CHAR_FORWARD_SLASH = exports.CHAR_DOT = exports.CHAR_LOWERCASE_Z = exports.CHAR_UPPERCASE_Z = exports.CHAR_LOWERCASE_A = exports.CHAR_UPPERCASE_A = void 0;
15
+ // Alphabet chars.
16
+ exports.CHAR_UPPERCASE_A = 65; /* A */
17
+ exports.CHAR_LOWERCASE_A = 97; /* a */
18
+ exports.CHAR_UPPERCASE_Z = 90; /* Z */
19
+ exports.CHAR_LOWERCASE_Z = 122; /* z */
20
+ // Non-alphabetic chars.
21
+ exports.CHAR_DOT = 46; /* . */
22
+ exports.CHAR_FORWARD_SLASH = 47; /* / */
23
+ exports.CHAR_BACKWARD_SLASH = 92; /* \ */
24
+ exports.CHAR_VERTICAL_LINE = 124; /* | */
25
+ exports.CHAR_COLON = 58; /* : */
26
+ exports.CHAR_QUESTION_MARK = 63; /* ? */
27
+ exports.CHAR_UNDERSCORE = 95; /* _ */
28
+ exports.CHAR_LINE_FEED = 10; /* \n */
29
+ exports.CHAR_CARRIAGE_RETURN = 13; /* \r */
30
+ exports.CHAR_TAB = 9; /* \t */
31
+ exports.CHAR_FORM_FEED = 12; /* \f */
32
+ exports.CHAR_EXCLAMATION_MARK = 33; /* ! */
33
+ exports.CHAR_HASH = 35; /* # */
34
+ exports.CHAR_SPACE = 32; /* */
35
+ exports.CHAR_NO_BREAK_SPACE = 160; /* \u00A0 */
36
+ exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279; /* \uFEFF */
37
+ exports.CHAR_LEFT_SQUARE_BRACKET = 91; /* [ */
38
+ exports.CHAR_RIGHT_SQUARE_BRACKET = 93; /* ] */
39
+ exports.CHAR_LEFT_ANGLE_BRACKET = 60; /* < */
40
+ exports.CHAR_RIGHT_ANGLE_BRACKET = 62; /* > */
41
+ exports.CHAR_LEFT_CURLY_BRACKET = 123; /* { */
42
+ exports.CHAR_RIGHT_CURLY_BRACKET = 125; /* } */
43
+ exports.CHAR_HYPHEN_MINUS = 45; /* - */
44
+ exports.CHAR_PLUS = 43; /* + */
45
+ exports.CHAR_DOUBLE_QUOTE = 34; /* " */
46
+ exports.CHAR_SINGLE_QUOTE = 39; /* ' */
47
+ exports.CHAR_PERCENT = 37; /* % */
48
+ exports.CHAR_SEMICOLON = 59; /* ; */
49
+ exports.CHAR_CIRCUMFLEX_ACCENT = 94; /* ^ */
50
+ exports.CHAR_GRAVE_ACCENT = 96; /* ` */
51
+ exports.CHAR_AT = 64; /* @ */
52
+ exports.CHAR_AMPERSAND = 38; /* & */
53
+ exports.CHAR_EQUAL = 61; /* = */
54
+ // Digits
55
+ exports.CHAR_0 = 48; /* 0 */
56
+ exports.CHAR_9 = 57; /* 9 */
57
+ });
@@ -0,0 +1,13 @@
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"], factory);
10
+ }
11
+ })(function (require, exports) {
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ });
@@ -0,0 +1,133 @@
1
+ // Copyright the Browserify authors. MIT License.
2
+ // Ported from https://github.com/browserify/path-browserify/
3
+ // This module is browser compatible.
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports", "./_constants.js"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.encodeWhitespace = exports._format = exports.normalizeString = exports.isWindowsDeviceRoot = exports.isPathSeparator = exports.isPosixPathSeparator = exports.assertPath = void 0;
15
+ const _constants_js_1 = require("./_constants.js");
16
+ function assertPath(path) {
17
+ if (typeof path !== "string") {
18
+ throw new TypeError(`Path must be a string. Received ${JSON.stringify(path)}`);
19
+ }
20
+ }
21
+ exports.assertPath = assertPath;
22
+ function isPosixPathSeparator(code) {
23
+ return code === _constants_js_1.CHAR_FORWARD_SLASH;
24
+ }
25
+ exports.isPosixPathSeparator = isPosixPathSeparator;
26
+ function isPathSeparator(code) {
27
+ return isPosixPathSeparator(code) || code === _constants_js_1.CHAR_BACKWARD_SLASH;
28
+ }
29
+ exports.isPathSeparator = isPathSeparator;
30
+ function isWindowsDeviceRoot(code) {
31
+ return ((code >= _constants_js_1.CHAR_LOWERCASE_A && code <= _constants_js_1.CHAR_LOWERCASE_Z) ||
32
+ (code >= _constants_js_1.CHAR_UPPERCASE_A && code <= _constants_js_1.CHAR_UPPERCASE_Z));
33
+ }
34
+ exports.isWindowsDeviceRoot = isWindowsDeviceRoot;
35
+ // Resolves . and .. elements in a path with directory names
36
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
37
+ let res = "";
38
+ let lastSegmentLength = 0;
39
+ let lastSlash = -1;
40
+ let dots = 0;
41
+ let code;
42
+ for (let i = 0, len = path.length; i <= len; ++i) {
43
+ if (i < len)
44
+ code = path.charCodeAt(i);
45
+ else if (isPathSeparator(code))
46
+ break;
47
+ else
48
+ code = _constants_js_1.CHAR_FORWARD_SLASH;
49
+ if (isPathSeparator(code)) {
50
+ if (lastSlash === i - 1 || dots === 1) {
51
+ // NOOP
52
+ }
53
+ else if (lastSlash !== i - 1 && dots === 2) {
54
+ if (res.length < 2 ||
55
+ lastSegmentLength !== 2 ||
56
+ res.charCodeAt(res.length - 1) !== _constants_js_1.CHAR_DOT ||
57
+ res.charCodeAt(res.length - 2) !== _constants_js_1.CHAR_DOT) {
58
+ if (res.length > 2) {
59
+ const lastSlashIndex = res.lastIndexOf(separator);
60
+ if (lastSlashIndex === -1) {
61
+ res = "";
62
+ lastSegmentLength = 0;
63
+ }
64
+ else {
65
+ res = res.slice(0, lastSlashIndex);
66
+ lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
67
+ }
68
+ lastSlash = i;
69
+ dots = 0;
70
+ continue;
71
+ }
72
+ else if (res.length === 2 || res.length === 1) {
73
+ res = "";
74
+ lastSegmentLength = 0;
75
+ lastSlash = i;
76
+ dots = 0;
77
+ continue;
78
+ }
79
+ }
80
+ if (allowAboveRoot) {
81
+ if (res.length > 0)
82
+ res += `${separator}..`;
83
+ else
84
+ res = "..";
85
+ lastSegmentLength = 2;
86
+ }
87
+ }
88
+ else {
89
+ if (res.length > 0)
90
+ res += separator + path.slice(lastSlash + 1, i);
91
+ else
92
+ res = path.slice(lastSlash + 1, i);
93
+ lastSegmentLength = i - lastSlash - 1;
94
+ }
95
+ lastSlash = i;
96
+ dots = 0;
97
+ }
98
+ else if (code === _constants_js_1.CHAR_DOT && dots !== -1) {
99
+ ++dots;
100
+ }
101
+ else {
102
+ dots = -1;
103
+ }
104
+ }
105
+ return res;
106
+ }
107
+ exports.normalizeString = normalizeString;
108
+ function _format(sep, pathObject) {
109
+ const dir = pathObject.dir || pathObject.root;
110
+ const base = pathObject.base ||
111
+ (pathObject.name || "") + (pathObject.ext || "");
112
+ if (!dir)
113
+ return base;
114
+ if (dir === pathObject.root)
115
+ return dir + base;
116
+ return dir + sep + base;
117
+ }
118
+ exports._format = _format;
119
+ const WHITESPACE_ENCODINGS = {
120
+ "\u0009": "%09",
121
+ "\u000A": "%0A",
122
+ "\u000B": "%0B",
123
+ "\u000C": "%0C",
124
+ "\u000D": "%0D",
125
+ "\u0020": "%20",
126
+ };
127
+ function encodeWhitespace(string) {
128
+ return string.replaceAll(/[\s]/g, (c) => {
129
+ return WHITESPACE_ENCODINGS[c] ?? c;
130
+ });
131
+ }
132
+ exports.encodeWhitespace = encodeWhitespace;
133
+ });
@@ -0,0 +1,49 @@
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", "./separator.js"], factory);
10
+ }
11
+ })(function (require, exports) {
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.common = void 0;
14
+ const separator_js_1 = require("./separator.js");
15
+ /** Determines the common path from a set of paths, using an optional separator,
16
+ * which defaults to the OS default separator.
17
+ *
18
+ * ```ts
19
+ * import { common } from "https://deno.land/std@$STD_VERSION/path/mod.ts";
20
+ * const p = common([
21
+ * "./deno/std/path/mod.ts",
22
+ * "./deno/std/fs/mod.ts",
23
+ * ]);
24
+ * console.log(p); // "./deno/std/"
25
+ * ```
26
+ */
27
+ function common(paths, sep = separator_js_1.SEP) {
28
+ const [first = "", ...remaining] = paths;
29
+ if (first === "" || remaining.length === 0) {
30
+ return first.substring(0, first.lastIndexOf(sep) + 1);
31
+ }
32
+ const parts = first.split(sep);
33
+ let endOfPrefix = parts.length;
34
+ for (const path of remaining) {
35
+ const compare = path.split(sep);
36
+ for (let i = 0; i < endOfPrefix; i++) {
37
+ if (compare[i] !== parts[i]) {
38
+ endOfPrefix = i;
39
+ }
40
+ }
41
+ if (endOfPrefix === 0) {
42
+ return "";
43
+ }
44
+ }
45
+ const prefix = parts.slice(0, endOfPrefix).join(sep);
46
+ return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`;
47
+ }
48
+ exports.common = common;
49
+ });