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,10 @@
1
+ /**
2
+ * All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions.
3
+ */
4
+ export declare class DenoStdInternalError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ /** Make an assertion, if not `true`, then throw. */
8
+ export declare function assert(expr: unknown, msg?: string): asserts expr;
9
+ /** Use this to assert unreachable code. */
10
+ export declare function unreachable(): never;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.unreachable = exports.assert = exports.DenoStdInternalError = void 0;
6
+ /**
7
+ * All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions.
8
+ */
9
+ class DenoStdInternalError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "DenoStdInternalError";
13
+ }
14
+ }
15
+ exports.DenoStdInternalError = DenoStdInternalError;
16
+ /** Make an assertion, if not `true`, then throw. */
17
+ function assert(expr, msg = "") {
18
+ if (!expr) {
19
+ throw new DenoStdInternalError(msg);
20
+ }
21
+ }
22
+ exports.assert = assert;
23
+ /** Use this to assert unreachable code. */
24
+ function unreachable() {
25
+ throw new DenoStdInternalError("unreachable");
26
+ }
27
+ exports.unreachable = unreachable;
@@ -0,0 +1,4 @@
1
+ export type OSType = "windows" | "linux" | "darwin" | "freebsd";
2
+ export declare const osType: OSType;
3
+ export declare const isWindows: boolean;
4
+ export declare const isLinux: boolean;
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isWindows = exports.osType = void 0;
27
- // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
26
+ exports.isLinux = exports.isWindows = exports.osType = void 0;
27
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
28
28
  // This module is browser compatible.
29
29
  const dntShim = __importStar(require("../../../../_dnt.shims.js"));
30
30
  exports.osType = (() => {
@@ -35,9 +35,10 @@ exports.osType = (() => {
35
35
  }
36
36
  // deno-lint-ignore no-explicit-any
37
37
  const { navigator } = dntShim.dntGlobalThis;
38
- if (navigator?.appVersion?.includes?.("Win") ?? false) {
38
+ if (navigator?.appVersion?.includes?.("Win")) {
39
39
  return "windows";
40
40
  }
41
41
  return "linux";
42
42
  })();
43
43
  exports.isWindows = exports.osType === "windows";
44
+ exports.isLinux = exports.osType === "linux";
@@ -0,0 +1,166 @@
1
+ /** Combines recursively all intersection types and returns a new single type. */
2
+ type Id<TRecord> = TRecord extends Record<string, unknown> ? TRecord extends infer InferredRecord ? {
3
+ [Key in keyof InferredRecord]: Id<InferredRecord[Key]>;
4
+ } : never : TRecord;
5
+ /** Converts a union type `A | B | C` into an intersection type `A & B & C`. */
6
+ type UnionToIntersection<TValue> = (TValue extends unknown ? (args: TValue) => unknown : never) extends (args: infer R) => unknown ? R extends Record<string, unknown> ? R : never : never;
7
+ type BooleanType = boolean | string | undefined;
8
+ type StringType = string | undefined;
9
+ type ArgType = StringType | BooleanType;
10
+ type Collectable = string | undefined;
11
+ type Negatable = string | undefined;
12
+ type UseTypes<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable> = undefined extends ((false extends TBooleans ? undefined : TBooleans) & TCollectable & TStrings) ? false : true;
13
+ /**
14
+ * Creates a record with all available flags with the corresponding type and
15
+ * default type.
16
+ */
17
+ type Values<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable, TNegatable extends Negatable, TDefault extends Record<string, unknown> | undefined, TAliases extends Aliases | undefined> = UseTypes<TBooleans, TStrings, TCollectable> extends true ? Record<string, unknown> & AddAliases<SpreadDefaults<CollectValues<TStrings, string, TCollectable, TNegatable> & RecursiveRequired<CollectValues<TBooleans, boolean, TCollectable>> & CollectUnknownValues<TBooleans, TStrings, TCollectable, TNegatable>, DedotRecord<TDefault>>, TAliases> : Record<string, any>;
18
+ type Aliases<TArgNames = string, TAliasNames extends string = string> = Partial<Record<Extract<TArgNames, string>, TAliasNames | ReadonlyArray<TAliasNames>>>;
19
+ type AddAliases<TArgs, TAliases extends Aliases | undefined> = {
20
+ [TArgName in keyof TArgs as AliasNames<TArgName, TAliases>]: TArgs[TArgName];
21
+ };
22
+ type AliasNames<TArgName, TAliases extends Aliases | undefined> = TArgName extends keyof TAliases ? string extends TAliases[TArgName] ? TArgName : TAliases[TArgName] extends string ? TArgName | TAliases[TArgName] : TAliases[TArgName] extends Array<string> ? TArgName | TAliases[TArgName][number] : TArgName : TArgName;
23
+ /**
24
+ * Spreads all default values of Record `TDefaults` into Record `TArgs`
25
+ * and makes default values required.
26
+ *
27
+ * **Example:**
28
+ * `SpreadValues<{ foo?: boolean, bar?: number }, { foo: number }>`
29
+ *
30
+ * **Result:** `{ foo: boolean | number, bar?: number }`
31
+ */
32
+ type SpreadDefaults<TArgs, TDefaults> = TDefaults extends undefined ? TArgs : TArgs extends Record<string, unknown> ? Omit<TArgs, keyof TDefaults> & {
33
+ [Default in keyof TDefaults]: Default extends keyof TArgs ? (TArgs[Default] & TDefaults[Default] | TDefaults[Default]) extends Record<string, unknown> ? NonNullable<SpreadDefaults<TArgs[Default], TDefaults[Default]>> : TDefaults[Default] | NonNullable<TArgs[Default]> : unknown;
34
+ } : never;
35
+ /**
36
+ * Defines the Record for the `default` option to add
37
+ * auto-suggestion support for IDE's.
38
+ */
39
+ type Defaults<TBooleans extends BooleanType, TStrings extends StringType> = Id<UnionToIntersection<Record<string, unknown> & MapTypes<TStrings, unknown> & MapTypes<TBooleans, unknown> & MapDefaults<TBooleans> & MapDefaults<TStrings>>>;
40
+ type MapDefaults<TArgNames extends ArgType> = Partial<Record<TArgNames extends string ? TArgNames : string, unknown>>;
41
+ type RecursiveRequired<TRecord> = TRecord extends Record<string, unknown> ? {
42
+ [Key in keyof TRecord]-?: RecursiveRequired<TRecord[Key]>;
43
+ } : TRecord;
44
+ /** Same as `MapTypes` but also supports collectable options. */
45
+ type CollectValues<TArgNames extends ArgType, TType, TCollectable extends Collectable, TNegatable extends Negatable = undefined> = UnionToIntersection<Extract<TArgNames, TCollectable> extends string ? (Exclude<TArgNames, TCollectable> extends never ? Record<never, never> : MapTypes<Exclude<TArgNames, TCollectable>, TType, TNegatable>) & (Extract<TArgNames, TCollectable> extends never ? Record<never, never> : RecursiveRequired<MapTypes<Extract<TArgNames, TCollectable>, Array<TType>, TNegatable>>) : MapTypes<TArgNames, TType, TNegatable>>;
46
+ /** Same as `Record` but also supports dotted and negatable options. */
47
+ type MapTypes<TArgNames extends ArgType, TType, TNegatable extends Negatable = undefined> = undefined extends TArgNames ? Record<never, never> : TArgNames extends `${infer Name}.${infer Rest}` ? {
48
+ [Key in Name]?: MapTypes<Rest, TType, TNegatable extends `${Name}.${infer Negate}` ? Negate : undefined>;
49
+ } : TArgNames extends string ? Partial<Record<TArgNames, TNegatable extends TArgNames ? TType | false : TType>> : Record<never, never>;
50
+ type CollectUnknownValues<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable, TNegatable extends Negatable> = UnionToIntersection<TCollectable extends TBooleans & TStrings ? Record<never, never> : DedotRecord<Record<Exclude<Extract<Exclude<TCollectable, TNegatable>, string>, Extract<TStrings | TBooleans, string>>, Array<unknown>> & Record<Exclude<Extract<Extract<TCollectable, TNegatable>, string>, Extract<TStrings | TBooleans, string>>, Array<unknown> | false>>>;
51
+ /** Converts `{ "foo.bar.baz": unknown }` into `{ foo: { bar: { baz: unknown } } }`. */
52
+ type DedotRecord<TRecord> = Record<string, unknown> extends TRecord ? TRecord : TRecord extends Record<string, unknown> ? UnionToIntersection<ValueOf<{
53
+ [Key in keyof TRecord]: Key extends string ? Dedot<Key, TRecord[Key]> : never;
54
+ }>> : TRecord;
55
+ type Dedot<TKey extends string, TValue> = TKey extends `${infer Name}.${infer Rest}` ? {
56
+ [Key in Name]: Dedot<Rest, TValue>;
57
+ } : {
58
+ [Key in TKey]: TValue;
59
+ };
60
+ type ValueOf<TValue> = TValue[keyof TValue];
61
+ /** The value returned from `parse`. */
62
+ export type Args<TArgs extends Record<string, unknown> = Record<string, any>, TDoubleDash extends boolean | undefined = undefined> = Id<TArgs & {
63
+ /** Contains all the arguments that didn't have an option associated with
64
+ * them. */
65
+ _: Array<string | number>;
66
+ } & (boolean extends TDoubleDash ? DoubleDash : true extends TDoubleDash ? Required<DoubleDash> : Record<never, never>)>;
67
+ type DoubleDash = {
68
+ /** Contains all the arguments that appear after the double dash: "--". */
69
+ "--"?: Array<string>;
70
+ };
71
+ /** The options for the `parse` call. */
72
+ export interface ParseOptions<TBooleans extends BooleanType = BooleanType, TStrings extends StringType = StringType, TCollectable extends Collectable = Collectable, TNegatable extends Negatable = Negatable, TDefault extends Record<string, unknown> | undefined = Record<string, unknown> | undefined, TAliases extends Aliases | undefined = Aliases | undefined, TDoubleDash extends boolean | undefined = boolean | undefined> {
73
+ /**
74
+ * When `true`, populate the result `_` with everything before the `--` and
75
+ * the result `['--']` with everything after the `--`.
76
+ *
77
+ * @default {false}
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * // $ deno run example.ts -- a arg1
82
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
83
+ * console.dir(parse(Deno.args, { "--": false }));
84
+ * // output: { _: [ "a", "arg1" ] }
85
+ * console.dir(parse(Deno.args, { "--": true }));
86
+ * // output: { _: [], --: [ "a", "arg1" ] }
87
+ * ```
88
+ */
89
+ "--"?: TDoubleDash;
90
+ /**
91
+ * An object mapping string names to strings or arrays of string argument
92
+ * names to use as aliases.
93
+ */
94
+ alias?: TAliases;
95
+ /**
96
+ * A boolean, string or array of strings to always treat as booleans. If
97
+ * `true` will treat all double hyphenated arguments without equal signs as
98
+ * `boolean` (e.g. affects `--foo`, not `-f` or `--foo=bar`).
99
+ * All `boolean` arguments will be set to `false` by default.
100
+ */
101
+ boolean?: TBooleans | ReadonlyArray<Extract<TBooleans, string>>;
102
+ /** An object mapping string argument names to default values. */
103
+ default?: TDefault & Defaults<TBooleans, TStrings>;
104
+ /**
105
+ * When `true`, populate the result `_` with everything after the first
106
+ * non-option.
107
+ */
108
+ stopEarly?: boolean;
109
+ /** A string or array of strings argument names to always treat as strings. */
110
+ string?: TStrings | ReadonlyArray<Extract<TStrings, string>>;
111
+ /**
112
+ * A string or array of strings argument names to always treat as arrays.
113
+ * Collectable options can be used multiple times. All values will be
114
+ * collected into one array. If a non-collectable option is used multiple
115
+ * times, the last value is used.
116
+ * All Collectable arguments will be set to `[]` by default.
117
+ */
118
+ collect?: TCollectable | ReadonlyArray<Extract<TCollectable, string>>;
119
+ /**
120
+ * A string or array of strings argument names which can be negated
121
+ * by prefixing them with `--no-`, like `--no-config`.
122
+ */
123
+ negatable?: TNegatable | ReadonlyArray<Extract<TNegatable, string>>;
124
+ /**
125
+ * A function which is invoked with a command line parameter not defined in
126
+ * the `options` configuration object. If the function returns `false`, the
127
+ * unknown option is not added to `parsedArgs`.
128
+ */
129
+ unknown?: (arg: string, key?: string, value?: unknown) => unknown;
130
+ }
131
+ /** Take a set of command line arguments, optionally with a set of options, and
132
+ * return an object representing the flags found in the passed arguments.
133
+ *
134
+ * By default, any arguments starting with `-` or `--` are considered boolean
135
+ * flags. If the argument name is followed by an equal sign (`=`) it is
136
+ * considered a key-value pair. Any arguments which could not be parsed are
137
+ * available in the `_` property of the returned object.
138
+ *
139
+ * By default, the flags module tries to determine the type of all arguments
140
+ * automatically and the return type of the `parse` method will have an index
141
+ * signature with `any` as value (`{ [x: string]: any }`).
142
+ *
143
+ * If the `string`, `boolean` or `collect` option is set, the return value of
144
+ * the `parse` method will be fully typed and the index signature of the return
145
+ * type will change to `{ [x: string]: unknown }`.
146
+ *
147
+ * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
148
+ *
149
+ * Numeric-looking arguments will be returned as numbers unless `options.string`
150
+ * or `options.boolean` is set for that argument name.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
155
+ * const parsedArgs = parse(Deno.args);
156
+ * ```
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
161
+ * const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
162
+ * // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
163
+ * ```
164
+ */
165
+ export declare function parse<TArgs extends Values<TBooleans, TStrings, TCollectable, TNegatable, TDefaults, TAliases>, TDoubleDash extends boolean | undefined = undefined, TBooleans extends BooleanType = undefined, TStrings extends StringType = undefined, TCollectable extends Collectable = undefined, TNegatable extends Negatable = undefined, TDefaults extends Record<string, unknown> | undefined = undefined, TAliases extends Aliases<TAliasArgNames, TAliasNames> | undefined = undefined, TAliasArgNames extends string = string, TAliasNames extends string = string>(args: string[], { "--": doubleDash, alias, boolean, default: defaults, stopEarly, string, collect, negatable, unknown, }?: ParseOptions<TBooleans, TStrings, TCollectable, TNegatable, TDefaults, TAliases, TDoubleDash>): Args<TArgs, TDoubleDash>;
166
+ export {};
@@ -1,8 +1,41 @@
1
1
  "use strict";
2
- // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
5
  exports.parse = void 0;
5
- const assert_js_1 = require("../_util/assert.js");
6
+ /**
7
+ * Command line arguments parser based on
8
+ * [minimist](https://github.com/minimistjs/minimist).
9
+ *
10
+ * This module is browser compatible.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
15
+ *
16
+ * console.dir(parse(Deno.args));
17
+ * ```
18
+ *
19
+ * ```sh
20
+ * $ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
21
+ * { _: [], a: 'beep', b: 'boop' }
22
+ * ```
23
+ *
24
+ * ```sh
25
+ * $ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
26
+ * { _: [ 'foo', 'bar', 'baz' ],
27
+ * x: 3,
28
+ * y: 4,
29
+ * n: 5,
30
+ * a: true,
31
+ * b: true,
32
+ * c: true,
33
+ * beep: 'boop' }
34
+ * ```
35
+ *
36
+ * @module
37
+ */
38
+ const asserts_js_1 = require("../_util/asserts.js");
6
39
  const { hasOwn } = Object;
7
40
  function get(obj, key) {
8
41
  if (hasOwn(obj, key)) {
@@ -11,7 +44,7 @@ function get(obj, key) {
11
44
  }
12
45
  function getForce(obj, key) {
13
46
  const v = get(obj, key);
14
- (0, assert_js_1.assert)(v != null);
47
+ (0, asserts_js_1.assert)(v != null);
15
48
  return v;
16
49
  }
17
50
  function isNumber(x) {
@@ -27,35 +60,52 @@ function hasKey(obj, keys) {
27
60
  o = (get(o, key) ?? {});
28
61
  });
29
62
  const key = keys[keys.length - 1];
30
- return key in o;
63
+ return hasOwn(o, key);
31
64
  }
32
- /** Take a set of command line arguments, with an optional set of options, and
33
- * return an object representation of those argument.
65
+ /** Take a set of command line arguments, optionally with a set of options, and
66
+ * return an object representing the flags found in the passed arguments.
67
+ *
68
+ * By default, any arguments starting with `-` or `--` are considered boolean
69
+ * flags. If the argument name is followed by an equal sign (`=`) it is
70
+ * considered a key-value pair. Any arguments which could not be parsed are
71
+ * available in the `_` property of the returned object.
72
+ *
73
+ * By default, the flags module tries to determine the type of all arguments
74
+ * automatically and the return type of the `parse` method will have an index
75
+ * signature with `any` as value (`{ [x: string]: any }`).
34
76
  *
77
+ * If the `string`, `boolean` or `collect` option is set, the return value of
78
+ * the `parse` method will be fully typed and the index signature of the return
79
+ * type will change to `{ [x: string]: unknown }`.
80
+ *
81
+ * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
82
+ *
83
+ * Numeric-looking arguments will be returned as numbers unless `options.string`
84
+ * or `options.boolean` is set for that argument name.
85
+ *
86
+ * @example
35
87
  * ```ts
36
- * import { parse } from "./mod.ts";
37
- * const parsedArgs = parse(Deno.args);
88
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
89
+ * const parsedArgs = parse(Deno.args);
90
+ * ```
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
95
+ * const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
96
+ * // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
38
97
  * ```
39
98
  */
40
- function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
99
+ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown = (i) => i, } = {}) {
100
+ const aliases = {};
41
101
  const flags = {
42
102
  bools: {},
43
103
  strings: {},
44
104
  unknownFn: unknown,
45
105
  allBools: false,
106
+ collect: {},
107
+ negatable: {},
46
108
  };
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
109
  if (alias !== undefined) {
60
110
  for (const key in alias) {
61
111
  const val = getForce(alias, key);
@@ -70,8 +120,29 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
70
120
  }
71
121
  }
72
122
  }
123
+ if (boolean !== undefined) {
124
+ if (typeof boolean === "boolean") {
125
+ flags.allBools = !!boolean;
126
+ }
127
+ else {
128
+ const booleanArgs = typeof boolean === "string"
129
+ ? [boolean]
130
+ : boolean;
131
+ for (const key of booleanArgs.filter(Boolean)) {
132
+ flags.bools[key] = true;
133
+ const alias = get(aliases, key);
134
+ if (alias) {
135
+ for (const al of alias) {
136
+ flags.bools[al] = true;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
73
142
  if (string !== undefined) {
74
- const stringArgs = typeof string === "string" ? [string] : string;
143
+ const stringArgs = typeof string === "string"
144
+ ? [string]
145
+ : string;
75
146
  for (const key of stringArgs.filter(Boolean)) {
76
147
  flags.strings[key] = true;
77
148
  const alias = get(aliases, key);
@@ -82,6 +153,34 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
82
153
  }
83
154
  }
84
155
  }
156
+ if (collect !== undefined) {
157
+ const collectArgs = typeof collect === "string"
158
+ ? [collect]
159
+ : collect;
160
+ for (const key of collectArgs.filter(Boolean)) {
161
+ flags.collect[key] = true;
162
+ const alias = get(aliases, key);
163
+ if (alias) {
164
+ for (const al of alias) {
165
+ flags.collect[al] = true;
166
+ }
167
+ }
168
+ }
169
+ }
170
+ if (negatable !== undefined) {
171
+ const negatableArgs = typeof negatable === "string"
172
+ ? [negatable]
173
+ : negatable;
174
+ for (const key of negatableArgs.filter(Boolean)) {
175
+ flags.negatable[key] = true;
176
+ const alias = get(aliases, key);
177
+ if (alias) {
178
+ for (const al of alias) {
179
+ flags.negatable[al] = true;
180
+ }
181
+ }
182
+ }
183
+ }
85
184
  const argv = { _: [] };
86
185
  function argDefined(key, arg) {
87
186
  return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
@@ -89,8 +188,9 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
89
188
  !!get(flags.strings, key) ||
90
189
  !!get(aliases, key));
91
190
  }
92
- function setKey(obj, keys, value) {
191
+ function setKey(obj, name, value, collect = true) {
93
192
  let o = obj;
193
+ const keys = name.split(".");
94
194
  keys.slice(0, -1).forEach(function (key) {
95
195
  if (get(o, key) === undefined) {
96
196
  o[key] = {};
@@ -98,11 +198,13 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
98
198
  o = get(o, key);
99
199
  });
100
200
  const key = keys[keys.length - 1];
101
- if (get(o, key) === undefined ||
102
- get(flags.bools, key) ||
103
- typeof get(o, key) === "boolean") {
201
+ const collectable = collect && !!get(flags.collect, name);
202
+ if (!collectable) {
104
203
  o[key] = value;
105
204
  }
205
+ else if (get(o, key) === undefined) {
206
+ o[key] = [value];
207
+ }
106
208
  else if (Array.isArray(get(o, key))) {
107
209
  o[key].push(value);
108
210
  }
@@ -110,26 +212,23 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
110
212
  o[key] = [get(o, key), value];
111
213
  }
112
214
  }
113
- function setArg(key, val, arg = undefined) {
215
+ function setArg(key, val, arg = undefined, collect) {
114
216
  if (arg && flags.unknownFn && !argDefined(key, arg)) {
115
217
  if (flags.unknownFn(arg, key, val) === false)
116
218
  return;
117
219
  }
118
220
  const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
119
- setKey(argv, key.split("."), value);
221
+ setKey(argv, key, value, collect);
120
222
  const alias = get(aliases, key);
121
223
  if (alias) {
122
224
  for (const x of alias) {
123
- setKey(argv, x.split("."), value);
225
+ setKey(argv, x, value, collect);
124
226
  }
125
227
  }
126
228
  }
127
229
  function aliasIsBoolean(key) {
128
230
  return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
129
231
  }
130
- for (const key of Object.keys(flags.bools)) {
131
- setArg(key, defaults[key] === undefined ? false : defaults[key]);
132
- }
133
232
  let notFlags = [];
134
233
  // all args after "--" are not parsed
135
234
  if (args.includes("--")) {
@@ -140,7 +239,7 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
140
239
  const arg = args[i];
141
240
  if (/^--.+=/.test(arg)) {
142
241
  const m = arg.match(/^--([^=]+)=(.*)$/s);
143
- (0, assert_js_1.assert)(m != null);
242
+ (0, asserts_js_1.assert)(m != null);
144
243
  const [, key, value] = m;
145
244
  if (flags.bools[key]) {
146
245
  const booleanValue = value !== "false";
@@ -150,14 +249,14 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
150
249
  setArg(key, value, arg);
151
250
  }
152
251
  }
153
- else if (/^--no-.+/.test(arg)) {
252
+ else if (/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))) {
154
253
  const m = arg.match(/^--no-(.+)/);
155
- (0, assert_js_1.assert)(m != null);
156
- setArg(m[1], false, arg);
254
+ (0, asserts_js_1.assert)(m != null);
255
+ setArg(m[1], false, arg, false);
157
256
  }
158
257
  else if (/^--.+/.test(arg)) {
159
258
  const m = arg.match(/^--(.+)/);
160
- (0, assert_js_1.assert)(m != null);
259
+ (0, asserts_js_1.assert)(m != null);
161
260
  const [, key] = m;
162
261
  const next = args[i + 1];
163
262
  if (next !== undefined &&
@@ -233,16 +332,27 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
233
332
  }
234
333
  }
235
334
  }
236
- for (const key of Object.keys(defaults)) {
335
+ for (const [key, value] of Object.entries(defaults)) {
237
336
  if (!hasKey(argv, key.split("."))) {
238
- setKey(argv, key.split("."), defaults[key]);
337
+ setKey(argv, key, value, false);
239
338
  if (aliases[key]) {
240
339
  for (const x of aliases[key]) {
241
- setKey(argv, x.split("."), defaults[key]);
340
+ setKey(argv, x, value, false);
242
341
  }
243
342
  }
244
343
  }
245
344
  }
345
+ for (const key of Object.keys(flags.bools)) {
346
+ if (!hasKey(argv, key.split("."))) {
347
+ const value = get(flags.collect, key) ? [] : false;
348
+ setKey(argv, key, value, false);
349
+ }
350
+ }
351
+ for (const key of Object.keys(flags.strings)) {
352
+ if (!hasKey(argv, key.split(".")) && get(flags.collect, key)) {
353
+ setKey(argv, key, [], false);
354
+ }
355
+ }
246
356
  if (doubleDash) {
247
357
  argv["--"] = [];
248
358
  for (const key of notFlags) {
@@ -0,0 +1,39 @@
1
+ export declare const CHAR_UPPERCASE_A = 65;
2
+ export declare const CHAR_LOWERCASE_A = 97;
3
+ export declare const CHAR_UPPERCASE_Z = 90;
4
+ export declare const CHAR_LOWERCASE_Z = 122;
5
+ export declare const CHAR_DOT = 46;
6
+ export declare const CHAR_FORWARD_SLASH = 47;
7
+ export declare const CHAR_BACKWARD_SLASH = 92;
8
+ export declare const CHAR_VERTICAL_LINE = 124;
9
+ export declare const CHAR_COLON = 58;
10
+ export declare const CHAR_QUESTION_MARK = 63;
11
+ export declare const CHAR_UNDERSCORE = 95;
12
+ export declare const CHAR_LINE_FEED = 10;
13
+ export declare const CHAR_CARRIAGE_RETURN = 13;
14
+ export declare const CHAR_TAB = 9;
15
+ export declare const CHAR_FORM_FEED = 12;
16
+ export declare const CHAR_EXCLAMATION_MARK = 33;
17
+ export declare const CHAR_HASH = 35;
18
+ export declare const CHAR_SPACE = 32;
19
+ export declare const CHAR_NO_BREAK_SPACE = 160;
20
+ export declare const CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279;
21
+ export declare const CHAR_LEFT_SQUARE_BRACKET = 91;
22
+ export declare const CHAR_RIGHT_SQUARE_BRACKET = 93;
23
+ export declare const CHAR_LEFT_ANGLE_BRACKET = 60;
24
+ export declare const CHAR_RIGHT_ANGLE_BRACKET = 62;
25
+ export declare const CHAR_LEFT_CURLY_BRACKET = 123;
26
+ export declare const CHAR_RIGHT_CURLY_BRACKET = 125;
27
+ export declare const CHAR_HYPHEN_MINUS = 45;
28
+ export declare const CHAR_PLUS = 43;
29
+ export declare const CHAR_DOUBLE_QUOTE = 34;
30
+ export declare const CHAR_SINGLE_QUOTE = 39;
31
+ export declare const CHAR_PERCENT = 37;
32
+ export declare const CHAR_SEMICOLON = 59;
33
+ export declare const CHAR_CIRCUMFLEX_ACCENT = 94;
34
+ export declare const CHAR_GRAVE_ACCENT = 96;
35
+ export declare const CHAR_AT = 64;
36
+ export declare const CHAR_AMPERSAND = 38;
37
+ export declare const CHAR_EQUAL = 61;
38
+ export declare const CHAR_0 = 48;
39
+ export declare const CHAR_9 = 57;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
3
  // Copyright the Browserify authors. MIT License.
3
4
  // Ported from https://github.com/browserify/path-browserify/
4
5
  // This module is browser compatible.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A parsed path object generated by path.parse() or consumed by path.format().
3
+ */
4
+ export interface ParsedPath {
5
+ /**
6
+ * The root of the path such as '/' or 'c:\'
7
+ */
8
+ root: string;
9
+ /**
10
+ * The full directory path such as '/home/user/dir' or 'c:\path\dir'
11
+ */
12
+ dir: string;
13
+ /**
14
+ * The file name including extension (if any) such as 'index.html'
15
+ */
16
+ base: string;
17
+ /**
18
+ * The file extension (if any) such as '.html'
19
+ */
20
+ ext: string;
21
+ /**
22
+ * The file name without extension (if any) such as 'index'
23
+ */
24
+ name: string;
25
+ }
26
+ export type FormatInputPathObject = Partial<ParsedPath>;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
- // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
3
  // This module is browser compatible.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import type { FormatInputPathObject } from "./_interface.js";
2
+ export declare function assertPath(path: string): void;
3
+ export declare function isPosixPathSeparator(code: number): boolean;
4
+ export declare function isPathSeparator(code: number): boolean;
5
+ export declare function isWindowsDeviceRoot(code: number): boolean;
6
+ export declare function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code: number) => boolean): string;
7
+ export declare function _format(sep: string, pathObject: FormatInputPathObject): string;
8
+ export declare function encodeWhitespace(string: string): string;
9
+ export declare function lastPathSegment(path: string, isSep: (char: number) => boolean, start?: number): string;
10
+ export declare function stripTrailingSeparators(segment: string, isSep: (char: number) => boolean): string;
11
+ export declare function stripSuffix(name: string, suffix: string): string;