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,21 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * 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.
5
+ */
6
+ export class DenoStdInternalError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "DenoStdInternalError";
10
+ }
11
+ }
12
+ /** Make an assertion, if not `true`, then throw. */
13
+ export function assert(expr, msg = "") {
14
+ if (!expr) {
15
+ throw new DenoStdInternalError(msg);
16
+ }
17
+ }
18
+ /** Use this to assert unreachable code. */
19
+ export function unreachable() {
20
+ throw new DenoStdInternalError("unreachable");
21
+ }
@@ -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;
@@ -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 * as dntShim from "../../../../_dnt.shims.js";
4
4
  export const osType = (() => {
@@ -9,9 +9,10 @@ export const osType = (() => {
9
9
  }
10
10
  // deno-lint-ignore no-explicit-any
11
11
  const { navigator } = dntShim.dntGlobalThis;
12
- if (navigator?.appVersion?.includes?.("Win") ?? false) {
12
+ if (navigator?.appVersion?.includes?.("Win")) {
13
13
  return "windows";
14
14
  }
15
15
  return "linux";
16
16
  })();
17
17
  export const isWindows = osType === "windows";
18
+ export const isLinux = 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,5 +1,38 @@
1
- // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2
- import { assert } from "../_util/assert.js";
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Command line arguments parser based on
5
+ * [minimist](https://github.com/minimistjs/minimist).
6
+ *
7
+ * This module is browser compatible.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
12
+ *
13
+ * console.dir(parse(Deno.args));
14
+ * ```
15
+ *
16
+ * ```sh
17
+ * $ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
18
+ * { _: [], a: 'beep', b: 'boop' }
19
+ * ```
20
+ *
21
+ * ```sh
22
+ * $ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
23
+ * { _: [ 'foo', 'bar', 'baz' ],
24
+ * x: 3,
25
+ * y: 4,
26
+ * n: 5,
27
+ * a: true,
28
+ * b: true,
29
+ * c: true,
30
+ * beep: 'boop' }
31
+ * ```
32
+ *
33
+ * @module
34
+ */
35
+ import { assert } from "../_util/asserts.js";
3
36
  const { hasOwn } = Object;
4
37
  function get(obj, key) {
5
38
  if (hasOwn(obj, key)) {
@@ -24,35 +57,52 @@ function hasKey(obj, keys) {
24
57
  o = (get(o, key) ?? {});
25
58
  });
26
59
  const key = keys[keys.length - 1];
27
- return key in o;
60
+ return hasOwn(o, key);
28
61
  }
29
- /** Take a set of command line arguments, with an optional set of options, and
30
- * return an object representation of those argument.
62
+ /** Take a set of command line arguments, optionally with a set of options, and
63
+ * return an object representing the flags found in the passed arguments.
64
+ *
65
+ * By default, any arguments starting with `-` or `--` are considered boolean
66
+ * flags. If the argument name is followed by an equal sign (`=`) it is
67
+ * considered a key-value pair. Any arguments which could not be parsed are
68
+ * available in the `_` property of the returned object.
69
+ *
70
+ * By default, the flags module tries to determine the type of all arguments
71
+ * automatically and the return type of the `parse` method will have an index
72
+ * signature with `any` as value (`{ [x: string]: any }`).
31
73
  *
74
+ * If the `string`, `boolean` or `collect` option is set, the return value of
75
+ * the `parse` method will be fully typed and the index signature of the return
76
+ * type will change to `{ [x: string]: unknown }`.
77
+ *
78
+ * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
79
+ *
80
+ * Numeric-looking arguments will be returned as numbers unless `options.string`
81
+ * or `options.boolean` is set for that argument name.
82
+ *
83
+ * @example
32
84
  * ```ts
33
- * import { parse } from "./mod.ts";
34
- * const parsedArgs = parse(Deno.args);
85
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
86
+ * const parsedArgs = parse(Deno.args);
87
+ * ```
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
92
+ * const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
93
+ * // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
35
94
  * ```
36
95
  */
37
- export function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
96
+ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown = (i) => i, } = {}) {
97
+ const aliases = {};
38
98
  const flags = {
39
99
  bools: {},
40
100
  strings: {},
41
101
  unknownFn: unknown,
42
102
  allBools: false,
103
+ collect: {},
104
+ negatable: {},
43
105
  };
44
- if (boolean !== undefined) {
45
- if (typeof boolean === "boolean") {
46
- flags.allBools = !!boolean;
47
- }
48
- else {
49
- const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
50
- for (const key of booleanArgs.filter(Boolean)) {
51
- flags.bools[key] = true;
52
- }
53
- }
54
- }
55
- const aliases = {};
56
106
  if (alias !== undefined) {
57
107
  for (const key in alias) {
58
108
  const val = getForce(alias, key);
@@ -67,8 +117,29 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
67
117
  }
68
118
  }
69
119
  }
120
+ if (boolean !== undefined) {
121
+ if (typeof boolean === "boolean") {
122
+ flags.allBools = !!boolean;
123
+ }
124
+ else {
125
+ const booleanArgs = typeof boolean === "string"
126
+ ? [boolean]
127
+ : boolean;
128
+ for (const key of booleanArgs.filter(Boolean)) {
129
+ flags.bools[key] = true;
130
+ const alias = get(aliases, key);
131
+ if (alias) {
132
+ for (const al of alias) {
133
+ flags.bools[al] = true;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
70
139
  if (string !== undefined) {
71
- const stringArgs = typeof string === "string" ? [string] : string;
140
+ const stringArgs = typeof string === "string"
141
+ ? [string]
142
+ : string;
72
143
  for (const key of stringArgs.filter(Boolean)) {
73
144
  flags.strings[key] = true;
74
145
  const alias = get(aliases, key);
@@ -79,6 +150,34 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
79
150
  }
80
151
  }
81
152
  }
153
+ if (collect !== undefined) {
154
+ const collectArgs = typeof collect === "string"
155
+ ? [collect]
156
+ : collect;
157
+ for (const key of collectArgs.filter(Boolean)) {
158
+ flags.collect[key] = true;
159
+ const alias = get(aliases, key);
160
+ if (alias) {
161
+ for (const al of alias) {
162
+ flags.collect[al] = true;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ if (negatable !== undefined) {
168
+ const negatableArgs = typeof negatable === "string"
169
+ ? [negatable]
170
+ : negatable;
171
+ for (const key of negatableArgs.filter(Boolean)) {
172
+ flags.negatable[key] = true;
173
+ const alias = get(aliases, key);
174
+ if (alias) {
175
+ for (const al of alias) {
176
+ flags.negatable[al] = true;
177
+ }
178
+ }
179
+ }
180
+ }
82
181
  const argv = { _: [] };
83
182
  function argDefined(key, arg) {
84
183
  return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
@@ -86,8 +185,9 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
86
185
  !!get(flags.strings, key) ||
87
186
  !!get(aliases, key));
88
187
  }
89
- function setKey(obj, keys, value) {
188
+ function setKey(obj, name, value, collect = true) {
90
189
  let o = obj;
190
+ const keys = name.split(".");
91
191
  keys.slice(0, -1).forEach(function (key) {
92
192
  if (get(o, key) === undefined) {
93
193
  o[key] = {};
@@ -95,11 +195,13 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
95
195
  o = get(o, key);
96
196
  });
97
197
  const key = keys[keys.length - 1];
98
- if (get(o, key) === undefined ||
99
- get(flags.bools, key) ||
100
- typeof get(o, key) === "boolean") {
198
+ const collectable = collect && !!get(flags.collect, name);
199
+ if (!collectable) {
101
200
  o[key] = value;
102
201
  }
202
+ else if (get(o, key) === undefined) {
203
+ o[key] = [value];
204
+ }
103
205
  else if (Array.isArray(get(o, key))) {
104
206
  o[key].push(value);
105
207
  }
@@ -107,26 +209,23 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
107
209
  o[key] = [get(o, key), value];
108
210
  }
109
211
  }
110
- function setArg(key, val, arg = undefined) {
212
+ function setArg(key, val, arg = undefined, collect) {
111
213
  if (arg && flags.unknownFn && !argDefined(key, arg)) {
112
214
  if (flags.unknownFn(arg, key, val) === false)
113
215
  return;
114
216
  }
115
217
  const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
116
- setKey(argv, key.split("."), value);
218
+ setKey(argv, key, value, collect);
117
219
  const alias = get(aliases, key);
118
220
  if (alias) {
119
221
  for (const x of alias) {
120
- setKey(argv, x.split("."), value);
222
+ setKey(argv, x, value, collect);
121
223
  }
122
224
  }
123
225
  }
124
226
  function aliasIsBoolean(key) {
125
227
  return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
126
228
  }
127
- for (const key of Object.keys(flags.bools)) {
128
- setArg(key, defaults[key] === undefined ? false : defaults[key]);
129
- }
130
229
  let notFlags = [];
131
230
  // all args after "--" are not parsed
132
231
  if (args.includes("--")) {
@@ -147,10 +246,10 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
147
246
  setArg(key, value, arg);
148
247
  }
149
248
  }
150
- else if (/^--no-.+/.test(arg)) {
249
+ else if (/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))) {
151
250
  const m = arg.match(/^--no-(.+)/);
152
251
  assert(m != null);
153
- setArg(m[1], false, arg);
252
+ setArg(m[1], false, arg, false);
154
253
  }
155
254
  else if (/^--.+/.test(arg)) {
156
255
  const m = arg.match(/^--(.+)/);
@@ -230,16 +329,27 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
230
329
  }
231
330
  }
232
331
  }
233
- for (const key of Object.keys(defaults)) {
332
+ for (const [key, value] of Object.entries(defaults)) {
234
333
  if (!hasKey(argv, key.split("."))) {
235
- setKey(argv, key.split("."), defaults[key]);
334
+ setKey(argv, key, value, false);
236
335
  if (aliases[key]) {
237
336
  for (const x of aliases[key]) {
238
- setKey(argv, x.split("."), defaults[key]);
337
+ setKey(argv, x, value, false);
239
338
  }
240
339
  }
241
340
  }
242
341
  }
342
+ for (const key of Object.keys(flags.bools)) {
343
+ if (!hasKey(argv, key.split("."))) {
344
+ const value = get(flags.collect, key) ? [] : false;
345
+ setKey(argv, key, value, false);
346
+ }
347
+ }
348
+ for (const key of Object.keys(flags.strings)) {
349
+ if (!hasKey(argv, key.split(".")) && get(flags.collect, key)) {
350
+ setKey(argv, key, [], false);
351
+ }
352
+ }
243
353
  if (doubleDash) {
244
354
  argv["--"] = [];
245
355
  for (const key of notFlags) {
@@ -1,3 +1,4 @@
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.
@@ -23,4 +23,4 @@ export interface ParsedPath {
23
23
  */
24
24
  name: string;
25
25
  }
26
- export declare type FormatInputPathObject = Partial<ParsedPath>;
26
+ export type FormatInputPathObject = Partial<ParsedPath>;
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+ export {};
@@ -6,3 +6,6 @@ export declare function isWindowsDeviceRoot(code: number): boolean;
6
6
  export declare function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code: number) => boolean): string;
7
7
  export declare function _format(sep: string, pathObject: FormatInputPathObject): string;
8
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;
@@ -1,3 +1,4 @@
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.
@@ -95,6 +96,8 @@ export function _format(sep, pathObject) {
95
96
  (pathObject.name || "") + (pathObject.ext || "");
96
97
  if (!dir)
97
98
  return base;
99
+ if (base === sep)
100
+ return dir;
98
101
  if (dir === pathObject.root)
99
102
  return dir + base;
100
103
  return dir + sep + base;
@@ -112,3 +115,47 @@ export function encodeWhitespace(string) {
112
115
  return WHITESPACE_ENCODINGS[c] ?? c;
113
116
  });
114
117
  }
118
+ export function lastPathSegment(path, isSep, start = 0) {
119
+ let matchedNonSeparator = false;
120
+ let end = path.length;
121
+ for (let i = path.length - 1; i >= start; --i) {
122
+ if (isSep(path.charCodeAt(i))) {
123
+ if (matchedNonSeparator) {
124
+ start = i + 1;
125
+ break;
126
+ }
127
+ }
128
+ else if (!matchedNonSeparator) {
129
+ matchedNonSeparator = true;
130
+ end = i + 1;
131
+ }
132
+ }
133
+ return path.slice(start, end);
134
+ }
135
+ export function stripTrailingSeparators(segment, isSep) {
136
+ if (segment.length <= 1) {
137
+ return segment;
138
+ }
139
+ let end = segment.length;
140
+ for (let i = segment.length - 1; i > 0; i--) {
141
+ if (isSep(segment.charCodeAt(i))) {
142
+ end = i;
143
+ }
144
+ else {
145
+ break;
146
+ }
147
+ }
148
+ return segment.slice(0, end);
149
+ }
150
+ export function stripSuffix(name, suffix) {
151
+ if (suffix.length >= name.length) {
152
+ return name;
153
+ }
154
+ const lenDiff = name.length - suffix.length;
155
+ for (let i = suffix.length - 1; i >= 0; --i) {
156
+ if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) {
157
+ return name;
158
+ }
159
+ }
160
+ return name.slice(0, -suffix.length);
161
+ }
@@ -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 { SEP } from "./separator.js";
4
4
  /** Determines the common path from a set of paths, using an optional separator,
@@ -1,19 +1,24 @@
1
1
  import type { OSType } from "../_util/os.js";
2
2
  export interface GlobOptions {
3
3
  /** Extended glob syntax.
4
- * See https://www.linuxjournal.com/content/bash-extended-globbing. Defaults
5
- * to true. */
4
+ * See https://www.linuxjournal.com/content/bash-extended-globbing.
5
+ *
6
+ * @default {true}
7
+ */
6
8
  extended?: boolean;
7
9
  /** Globstar syntax.
8
10
  * See https://www.linuxjournal.com/content/globstar-new-bash-globbing-option.
9
- * If false, `**` is treated like `*`. Defaults to true. */
11
+ * If false, `**` is treated like `*`.
12
+ *
13
+ * @default {true}
14
+ */
10
15
  globstar?: boolean;
11
- /** Whether globstar should be case insensitive. */
16
+ /** Whether globstar should be case-insensitive. */
12
17
  caseInsensitive?: boolean;
13
18
  /** Operating system. Defaults to the native OS. */
14
19
  os?: OSType;
15
20
  }
16
- export declare type GlobToRegExpOptions = GlobOptions;
21
+ export type GlobToRegExpOptions = GlobOptions;
17
22
  /** Convert a glob string to a regular expression.
18
23
  *
19
24
  * Tries to match bash glob expansion as closely as possible.
@@ -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, osType } from "../_util/os.js";
4
4
  import { SEP, SEP_PATTERN } from "./separator.js";
@@ -2,7 +2,9 @@ import * as _win32 from "./win32.js";
2
2
  import * as _posix from "./posix.js";
3
3
  export declare const win32: typeof _win32;
4
4
  export declare const posix: typeof _posix;
5
- export declare const basename: typeof _posix.basename | typeof _win32.basename, delimiter: string, dirname: typeof _posix.dirname | typeof _win32.dirname, extname: typeof _posix.extname | typeof _win32.extname, format: typeof _posix.format | typeof _win32.format, fromFileUrl: typeof _posix.fromFileUrl | typeof _win32.fromFileUrl, isAbsolute: typeof _win32.isAbsolute | typeof _posix.isAbsolute, join: typeof _posix.join | typeof _win32.join, normalize: typeof _win32.normalize | typeof _posix.normalize, parse: typeof _posix.parse | typeof _win32.parse, relative: typeof _posix.relative | typeof _win32.relative, resolve: typeof _win32.resolve | typeof _posix.resolve, sep: string, toFileUrl: typeof _posix.toFileUrl | typeof _win32.toFileUrl, toNamespacedPath: typeof _posix.toNamespacedPath | typeof _win32.toNamespacedPath;
5
+ export declare const basename: typeof _posix.basename | typeof _win32.basename, delimiter: string, dirname: typeof _posix.dirname | typeof _win32.dirname, extname: typeof _posix.extname | typeof _win32.extname, format: typeof _posix.format | typeof _win32.format, fromFileUrl: typeof _posix.fromFileUrl | typeof _win32.fromFileUrl, isAbsolute: typeof _win32.isAbsolute | typeof _posix.isAbsolute, join: typeof _posix.join | typeof _win32.join, normalize: typeof _win32.normalize | typeof _posix.normalize, parse: typeof _posix.parse | typeof _win32.parse, relative: typeof _posix.relative | typeof _win32.relative, resolve: typeof _win32.resolve | typeof _posix.resolve, toFileUrl: typeof _posix.toFileUrl | typeof _win32.toFileUrl, toNamespacedPath: typeof _posix.toNamespacedPath | typeof _win32.toNamespacedPath;
6
+ /** @deprecated (will be removed after 0.188.0) Use SEP intead. */
7
+ export declare const sep: string;
6
8
  export * from "./common.js";
7
9
  export { SEP, SEP_PATTERN } from "./separator.js";
8
10
  export * from "./_interface.js";