keep-a-changelog 2.0.1 → 2.1.0

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