args-tokens 0.15.1 → 0.16.1

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.
package/lib/index.d.ts CHANGED
@@ -1,40 +1,43 @@
1
- import { ArgToken, ParserOptions, parseArgs$1 as parseArgs } from "./parser.d-nUUBO6hL.js";
2
- import { ArgOptionSchema, ArgOptions, ArgValues, OptionResolveError$1 as OptionResolveError, OptionResolveErrorType, ResolveArgsOptions, resolveArgs$1 as resolveArgs } from "./resolver.d-D_30OItP.js";
1
+ import { ArgToken, ParserOptions, parseArgs$1 as parseArgs } from "./parser-Bx112mWZ.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgValues, OptionResolveError$1 as OptionResolveError, OptionResolveErrorType, ResolveArgsOptions, resolveArgs$1 as resolveArgs } from "./resolver-ByBRRKOK.js";
3
3
 
4
4
  //#region src/parse.d.ts
5
5
  /**
6
6
  * Parse options for {@link parse} function.
7
7
  */
8
+ /**
9
+ * Parse options for {@link parse} function.
10
+ */
8
11
  interface ParseOptions<O extends ArgOptions> extends ParserOptions, ResolveArgsOptions {
9
- /**
10
- * Command line options, about details see {@link ArgOptions}.
11
- */
12
- options?: O;
12
+ /**
13
+ * Command line options, about details see {@link ArgOptions}.
14
+ */
15
+ options?: O;
13
16
  }
14
17
  /**
15
18
  * Parsed command line arguments.
16
19
  */
17
20
  type ParsedArgs<T extends ArgOptions> = {
18
- /**
19
- * Parsed values, same as `values` in {@link resolveArgs}.
20
- */
21
- values: ArgValues<T>
22
- /**
23
- * Positional arguments, same as `positionals` in {@link resolveArgs}.
24
- */
25
- positionals: string[]
26
- /**
27
- * Rest arguments, same as `rest` in {@link resolveArgs}.
28
- */
29
- rest: string[]
30
- /**
31
- * Validation errors, same as `errors` in {@link resolveArgs}.
32
- */
33
- error: AggregateError | undefined
34
- /**
35
- * Argument tokens, same as `tokens` which is parsed by {@link parseArgs}.
36
- */
37
- tokens: ArgToken[]
21
+ /**
22
+ * Parsed values, same as `values` in {@link resolveArgs}.
23
+ */
24
+ values: ArgValues<T>;
25
+ /**
26
+ * Positional arguments, same as `positionals` in {@link resolveArgs}.
27
+ */
28
+ positionals: string[];
29
+ /**
30
+ * Rest arguments, same as `rest` in {@link resolveArgs}.
31
+ */
32
+ rest: string[];
33
+ /**
34
+ * Validation errors, same as `errors` in {@link resolveArgs}.
35
+ */
36
+ error: AggregateError | undefined;
37
+ /**
38
+ * Argument tokens, same as `tokens` which is parsed by {@link parseArgs}.
39
+ */
40
+ tokens: ArgToken[];
38
41
  };
39
42
  /**
40
43
  * Parse command line arguments.
@@ -51,7 +54,5 @@ type ParsedArgs<T extends ArgOptions> = {
51
54
  * @param options - parse options, about details see {@link ParseOptions}
52
55
  * @returns An object that contains the values of the arguments, positional arguments, {@link AggregateError | validation errors}, and {@link ArgToken | argument tokens}.
53
56
  */
54
- declare function parse<O extends ArgOptions>(args: string[], options?: ParseOptions<O>): ParsedArgs<O>;
55
-
56
- //#endregion
57
+ declare function parse<O extends ArgOptions>(args: string[], options?: ParseOptions<O>): ParsedArgs<O>; //#endregion
57
58
  export { ArgOptionSchema, ArgOptions, ArgToken, ArgValues, OptionResolveError, OptionResolveErrorType, ParseOptions, ParsedArgs, ParserOptions, ResolveArgsOptions, parse, parseArgs, resolveArgs };
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { parseArgs } from "./parser-DxH6Mf-o.js";
2
- import { OptionResolveError, resolveArgs } from "./resolver-D4hvuBLP.js";
1
+ import { parseArgs } from "./parser-Dr4iAGaX.js";
2
+ import { OptionResolveError, resolveArgs } from "./resolver-B89Gv70Z.js";
3
3
 
4
4
  //#region src/parse.ts
5
5
  const DEFAULT_OPTIONS = {
@@ -12,10 +12,25 @@ const DEFAULT_OPTIONS = {
12
12
  short: "v"
13
13
  }
14
14
  };
15
+ /**
16
+ * Parse command line arguments.
17
+ * This function is a convenient API, that is used {@link parseArgs} and {@link resolveArgs} in internal.
18
+ * @example
19
+ * ```js
20
+ * import { parse } from 'args-tokens'
21
+ *
22
+ * const { values, positionals } = parse(process.argv.slice(2))
23
+ * console.log('values', values)
24
+ * console.log('positionals', positionals)
25
+ * ```
26
+ * @param args - command line arguments
27
+ * @param options - parse options, about details see {@link ParseOptions}
28
+ * @returns An object that contains the values of the arguments, positional arguments, {@link AggregateError | validation errors}, and {@link ArgToken | argument tokens}.
29
+ */
15
30
  function parse(args, options = {}) {
16
- const { options: argOptions, allowCompatible = false, allowNegative = false } = options;
31
+ const { options: argOptions, allowCompatible = false } = options;
17
32
  const tokens = parseArgs(args, { allowCompatible });
18
- return Object.assign(Object.create(null), resolveArgs(argOptions || DEFAULT_OPTIONS, tokens, { allowNegative }), { tokens });
33
+ return Object.assign(Object.create(null), resolveArgs(argOptions || DEFAULT_OPTIONS, tokens), { tokens });
19
34
  }
20
35
 
21
36
  //#endregion
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/parser.d.ts
3
2
  /**
4
3
  * Entry point of argument parser.
@@ -18,52 +17,46 @@
18
17
  * - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
19
18
  * - `positional`: positional token
20
19
  */
21
- /**
22
- * Argument token Kind.
23
- * - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
24
- * - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
25
- * - `positional`: positional token
26
- */
27
20
  type ArgTokenKind = "option" | "option-terminator" | "positional";
28
21
  /**
29
22
  * Argument token.
30
23
  */
31
24
  interface ArgToken {
32
- /**
33
- * Argument token kind.
34
- */
35
- kind: ArgTokenKind;
36
- /**
37
- * Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1.
38
- */
39
- index: number;
40
- /**
41
- * Option name, e.g. `--foo` => `foo`, `-x` => `x`.
42
- */
43
- name?: string;
44
- /**
45
- * Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`.
46
- */
47
- rawName?: string;
48
- /**
49
- * Option value, e.g. `--foo=bar` => `bar`, `-x=bar` => `bar`.
50
- * If the `allowCompatible` option is `true`, short option value will be same as Node.js `parseArgs` behavior.
51
- */
52
- value?: string;
53
- /**
54
- * Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
55
- */
56
- inlineValue?: boolean;
25
+ /**
26
+ * Argument token kind.
27
+ */
28
+ kind: ArgTokenKind;
29
+ /**
30
+ * Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1.
31
+ */
32
+ index: number;
33
+ /**
34
+ * Option name, e.g. `--foo` => `foo`, `-x` => `x`.
35
+ */
36
+ name?: string;
37
+ /**
38
+ * Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`.
39
+ */
40
+ rawName?: string;
41
+ /**
42
+ * Option value, e.g. `--foo=bar` => `bar`, `-x=bar` => `bar`.
43
+ * If the `allowCompatible` option is `true`, short option value will be same as Node.js `parseArgs` behavior.
44
+ */
45
+ value?: string;
46
+ /**
47
+ * Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
48
+ */
49
+ inlineValue?: boolean;
57
50
  }
58
51
  /**
59
52
  * Parser Options.
60
53
  */
61
54
  interface ParserOptions {
62
- /**
63
- * [Node.js parseArgs](https://nodejs.org/api/util.html#parseargs-tokens) tokens compatible mode.
64
- * @default false
65
- */
66
- allowCompatible?: boolean;
55
+ /**
56
+ * [Node.js parseArgs](https://nodejs.org/api/util.html#parseargs-tokens) tokens compatible mode.
57
+ * @default false
58
+ */
59
+ allowCompatible?: boolean;
67
60
  }
68
61
  /**
69
62
  * Parse command line arguments.
@@ -93,7 +86,5 @@ declare function isShortOption(arg: string): boolean;
93
86
  * @param arg the argument to check
94
87
  * @returns whether `arg` is a long option prefix.
95
88
  */
96
- declare function hasLongOptionPrefix(arg: string): boolean;
97
-
98
- //#endregion
89
+ declare function hasLongOptionPrefix(arg: string): boolean; //#endregion
99
90
  export { ArgToken, ParserOptions, hasLongOptionPrefix as hasLongOptionPrefix$1, isShortOption as isShortOption$1, parseArgs as parseArgs$1 };
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/parser.ts
3
2
  const HYPHEN_CHAR = "-";
4
3
  const HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
@@ -7,6 +6,22 @@ const EQUAL_CODE = EQUAL_CHAR.codePointAt(0);
7
6
  const TERMINATOR = "--";
8
7
  const SHORT_OPTION_PREFIX = HYPHEN_CHAR;
9
8
  const LONG_OPTION_PREFIX = "--";
9
+ /**
10
+ * Parse command line arguments.
11
+ * @example
12
+ * ```js
13
+ * import { parseArgs } from 'args-tokens' // for Node.js and Bun
14
+ * // import { parseArgs } from 'jsr:@kazupon/args-tokens' // for Deno
15
+ *
16
+ * const tokens = parseArgs(['--foo', 'bar', '-x', '--bar=baz'])
17
+ * // do something with using tokens
18
+ * // ...
19
+ * console.log('tokens:', tokens)
20
+ * ```
21
+ * @param args command line arguments
22
+ * @param options parse options
23
+ * @returns Argument tokens.
24
+ */
10
25
  function parseArgs(args, options = {}) {
11
26
  const { allowCompatible = false } = options;
12
27
  const tokens = [];
@@ -120,6 +135,11 @@ function parseArgs(args, options = {}) {
120
135
  }
121
136
  return tokens;
122
137
  }
138
+ /**
139
+ * Check if `arg` is a short option (e.g. `-f`).
140
+ * @param arg the argument to check
141
+ * @returns whether `arg` is a short option.
142
+ */
123
143
  function isShortOption(arg) {
124
144
  return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
125
145
  }
@@ -150,6 +170,11 @@ function isLongOption(arg) {
150
170
  function isLongOptionAndValue(arg) {
151
171
  return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
152
172
  }
173
+ /**
174
+ * Check if `arg` is a long option prefix (e.g. `--`).
175
+ * @param arg the argument to check
176
+ * @returns whether `arg` is a long option prefix.
177
+ */
153
178
  function hasLongOptionPrefix(arg) {
154
179
  return arg.length > 2 && ~arg.indexOf(LONG_OPTION_PREFIX);
155
180
  }
package/lib/parser.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { ArgToken, ParserOptions, hasLongOptionPrefix$1 as hasLongOptionPrefix, isShortOption$1 as isShortOption, parseArgs$1 as parseArgs } from "./parser.d-nUUBO6hL.js";
2
-
1
+ import { ArgToken, ParserOptions, hasLongOptionPrefix$1 as hasLongOptionPrefix, isShortOption$1 as isShortOption, parseArgs$1 as parseArgs } from "./parser-Bx112mWZ.js";
3
2
  export { ArgToken, ParserOptions, hasLongOptionPrefix, isShortOption, parseArgs };
package/lib/parser.js CHANGED
@@ -1,3 +1,3 @@
1
- import { hasLongOptionPrefix, isShortOption, parseArgs } from "./parser-DxH6Mf-o.js";
1
+ import { hasLongOptionPrefix, isShortOption, parseArgs } from "./parser-Dr4iAGaX.js";
2
2
 
3
3
  export { hasLongOptionPrefix, isShortOption, parseArgs };
@@ -1,7 +1,14 @@
1
- import { hasLongOptionPrefix, isShortOption } from "./parser-DxH6Mf-o.js";
1
+ import { hasLongOptionPrefix, isShortOption } from "./parser-Dr4iAGaX.js";
2
2
 
3
3
  //#region src/resolver.ts
4
- function resolveArgs(options, tokens, { optionGrouping = false, allowNegative = false } = {}) {
4
+ /**
5
+ * Resolve command line arguments.
6
+ * @param options - An options that contains {@link ArgOptionSchema | options schema}.
7
+ * @param tokens - An array of {@link ArgToken | tokens}.
8
+ * @param resolveArgsOptions - An options that contains {@link resolveArgsOptions | resolve arguments options}.
9
+ * @returns An object that contains the values of the arguments, positional arguments, rest arguments, and {@link AggregateError | validation errors}.
10
+ */
11
+ function resolveArgs(options, tokens, { optionGrouping = false } = {}) {
5
12
  const positionals = [];
6
13
  const rest = [];
7
14
  const longOptionTokens = [];
@@ -100,7 +107,7 @@ function resolveArgs(options, tokens, { optionGrouping = false, allowNegative =
100
107
  const values = Object.create(null);
101
108
  const errors = [];
102
109
  function checkTokenName(option, schema, token) {
103
- return token.name === (schema.type === "boolean" ? allowNegative && token.name?.startsWith("no-") ? `no-${option}` : option : option);
110
+ return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
104
111
  }
105
112
  for (const [option, schema] of Object.entries(options)) {
106
113
  if (schema.required) {
@@ -126,7 +133,7 @@ function resolveArgs(options, tokens, { optionGrouping = false, allowNegative =
126
133
  continue;
127
134
  }
128
135
  }
129
- values[option] = resolveOptionValue(token, schema, allowNegative);
136
+ values[option] = resolveOptionValue(token, schema);
130
137
  continue;
131
138
  }
132
139
  }
@@ -162,6 +169,10 @@ function resolveArgs(options, tokens, { optionGrouping = false, allowNegative =
162
169
  function createRequireError(option, schema) {
163
170
  return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
164
171
  }
172
+ /**
173
+ * An error that occurs when resolving options.
174
+ * This error is thrown when the option is not valid.
175
+ */
165
176
  var OptionResolveError = class extends Error {
166
177
  name;
167
178
  schema;
@@ -198,9 +209,9 @@ function isNumeric(str) {
198
209
  function createTypeError(option, schema) {
199
210
  return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, "type", schema);
200
211
  }
201
- function resolveOptionValue(token, schema, allowNegative = false) {
212
+ function resolveOptionValue(token, schema) {
202
213
  if (token.value) return schema.type === "number" ? +token.value : token.value;
203
- if (schema.type === "boolean") return allowNegative && token.name.startsWith("no-") ? false : true;
214
+ if (schema.type === "boolean") return schema.negatable && token.name.startsWith("no-") ? false : true;
204
215
  return schema.type === "number" ? +(schema.default || "") : schema.default;
205
216
  }
206
217
 
@@ -0,0 +1,119 @@
1
+ import { ArgToken } from "./parser-Bx112mWZ.js";
2
+
3
+ //#region src/resolver.d.ts
4
+ /**
5
+ * An option schema for an argument.
6
+ * This schema is similar to the schema of the `node:utils`.
7
+ * difference is that:
8
+ * - `multiple` property is not supported
9
+ * - `required` property and `description` property are added
10
+ * - `type` is not only 'string' and 'boolean', but also 'number' and 'enum' too.
11
+ * - `default` property type, not support multiple types
12
+ */
13
+ /**
14
+ * An option schema for an argument.
15
+ * This schema is similar to the schema of the `node:utils`.
16
+ * difference is that:
17
+ * - `multiple` property is not supported
18
+ * - `required` property and `description` property are added
19
+ * - `type` is not only 'string' and 'boolean', but also 'number' and 'enum' too.
20
+ * - `default` property type, not support multiple types
21
+ */
22
+ interface ArgOptionSchema {
23
+ /**
24
+ * Type of argument.
25
+ */
26
+ type: "string" | "boolean" | "number" | "enum";
27
+ /**
28
+ * A single character alias for the option.
29
+ */
30
+ short?: string;
31
+ /**
32
+ * A description of the argument.
33
+ */
34
+ description?: string;
35
+ /**
36
+ * Whether the argument is required or not.
37
+ */
38
+ required?: true;
39
+ /**
40
+ * Whether the negatable option for `boolean` type
41
+ */
42
+ negatable?: boolean;
43
+ /**
44
+ * The allowed values of the argument, and string only. This property is only used when the type is 'enum'.
45
+ */
46
+ choices?: string[] | readonly string[];
47
+ /**
48
+ * The default value of the argument.
49
+ * if the type is 'enum', the default value must be one of the allowed values.
50
+ */
51
+ default?: string | boolean | number;
52
+ }
53
+ /**
54
+ * An object that contains {@link ArgOptionSchema | options schema}.
55
+ */
56
+ interface ArgOptions {
57
+ [option: string]: ArgOptionSchema;
58
+ }
59
+ /**
60
+ * An object that contains the values of the arguments.
61
+ */
62
+ type ArgValues<T> = T extends ArgOptions ? ResolveArgValues<T, { [Option in keyof T]: ExtractOptionValue<T[Option]> }> : {
63
+ [option: string]: string | boolean | number | undefined;
64
+ };
65
+ /**
66
+ * @internal
67
+ */
68
+ type ExtractOptionValue<O extends ArgOptionSchema> = O["type"] extends "string" ? string : O["type"] extends "boolean" ? boolean : O["type"] extends "number" ? number : O["type"] extends "enum" ? O["choices"] extends string[] | readonly string[] ? O["choices"][number] : never : string | boolean | number;
69
+ /**
70
+ * @internal
71
+ */
72
+ type ResolveArgValues<O extends ArgOptions, V extends Record<keyof O, unknown>> = { -readonly [Option in keyof O]?: V[Option] } & FilterArgs<O, V, "default"> & FilterArgs<O, V, "required"> extends infer P ? { [K in keyof P]: P[K] } : never;
73
+ /**
74
+ * @internal
75
+ */
76
+ type FilterArgs<O extends ArgOptions, V extends Record<keyof O, unknown>, K extends keyof ArgOptionSchema> = { [Option in keyof O as O[Option][K] extends {} ? Option : never]: V[Option] };
77
+ /**
78
+ * An options for {@link resolveArgs | resolve arguments}.
79
+ */
80
+ interface ResolveArgsOptions {
81
+ /**
82
+ * Whether to group short options.
83
+ * @default false
84
+ * @see guideline 5 in https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap12.html
85
+ */
86
+ optionGrouping?: boolean;
87
+ }
88
+ /**
89
+ * Resolve command line arguments.
90
+ * @param options - An options that contains {@link ArgOptionSchema | options schema}.
91
+ * @param tokens - An array of {@link ArgToken | tokens}.
92
+ * @param resolveArgsOptions - An options that contains {@link resolveArgsOptions | resolve arguments options}.
93
+ * @returns An object that contains the values of the arguments, positional arguments, rest arguments, and {@link AggregateError | validation errors}.
94
+ */
95
+ declare function resolveArgs<T extends ArgOptions>(options: T, tokens: ArgToken[], {
96
+ optionGrouping
97
+ }?: ResolveArgsOptions): {
98
+ values: ArgValues<T>;
99
+ positionals: string[];
100
+ rest: string[];
101
+ error: AggregateError | undefined;
102
+ };
103
+ /**
104
+ * An error type for {@link OptionResolveError}.
105
+ */
106
+ type OptionResolveErrorType = "type" | "required";
107
+ /**
108
+ * An error that occurs when resolving options.
109
+ * This error is thrown when the option is not valid.
110
+ */
111
+ declare class OptionResolveError extends Error {
112
+ name: string;
113
+ schema: ArgOptionSchema;
114
+ type: OptionResolveErrorType;
115
+ constructor(message: string, name: string, type: OptionResolveErrorType, schema: ArgOptionSchema);
116
+ }
117
+
118
+ //#endregion
119
+ export { ArgOptionSchema, ArgOptions, ArgValues, ExtractOptionValue, FilterArgs, OptionResolveError as OptionResolveError$1, OptionResolveErrorType, ResolveArgValues, ResolveArgsOptions, resolveArgs as resolveArgs$1 };
package/lib/resolver.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import "./parser.d-nUUBO6hL.js";
2
- import { ArgOptionSchema, ArgOptions, ArgValues, ExtractOptionValue, FilterArgs, OptionResolveError$1 as OptionResolveError, OptionResolveErrorType, ResolveArgValues, ResolveArgsOptions, resolveArgs$1 as resolveArgs } from "./resolver.d-D_30OItP.js";
3
-
1
+ import "./parser-Bx112mWZ.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgValues, ExtractOptionValue, FilterArgs, OptionResolveError$1 as OptionResolveError, OptionResolveErrorType, ResolveArgValues, ResolveArgsOptions, resolveArgs$1 as resolveArgs } from "./resolver-ByBRRKOK.js";
4
3
  export { ArgOptionSchema, ArgOptions, ArgValues, ExtractOptionValue, FilterArgs, OptionResolveError, OptionResolveErrorType, ResolveArgValues, ResolveArgsOptions, resolveArgs };
package/lib/resolver.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./parser-DxH6Mf-o.js";
2
- import { OptionResolveError, resolveArgs } from "./resolver-D4hvuBLP.js";
1
+ import "./parser-Dr4iAGaX.js";
2
+ import { OptionResolveError, resolveArgs } from "./resolver-B89Gv70Z.js";
3
3
 
4
4
  export { OptionResolveError, resolveArgs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "args-tokens",
3
3
  "description": "parseArgs tokens compatibility and more high-performance parser",
4
- "version": "0.15.1",
4
+ "version": "0.16.1",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -68,29 +68,29 @@
68
68
  "@eslint/markdown": "^6.4.0",
69
69
  "@kazupon/eslint-config": "^0.29.0",
70
70
  "@kazupon/prettier-config": "^0.1.1",
71
- "@types/node": "^22.14.1",
72
- "@vitest/eslint-plugin": "^1.1.43",
71
+ "@types/node": "^22.15.3",
72
+ "@vitest/eslint-plugin": "^1.1.44",
73
73
  "bumpp": "^10.1.0",
74
- "deno": "^2.2.11",
75
- "eslint": "^9.25.0",
74
+ "deno": "^2.3.1",
75
+ "eslint": "^9.26.0",
76
76
  "eslint-config-prettier": "^10.1.2",
77
77
  "eslint-plugin-jsonc": "^2.20.0",
78
78
  "eslint-plugin-promise": "^7.2.1",
79
79
  "eslint-plugin-regexp": "^2.7.0",
80
- "eslint-plugin-unicorn": "^58.0.0",
81
- "eslint-plugin-yml": "^1.17.0",
80
+ "eslint-plugin-unicorn": "^59.0.0",
81
+ "eslint-plugin-yml": "^1.18.0",
82
82
  "gh-changelogen": "^0.2.8",
83
83
  "jsr": "^0.13.4",
84
- "knip": "^5.50.5",
84
+ "jsr-exports-lint": "^0.2.0",
85
+ "knip": "^5.52.0",
85
86
  "lint-staged": "^15.5.1",
86
87
  "mitata": "^1.0.34",
87
88
  "pkg-pr-new": "^0.0.43",
88
89
  "prettier": "^3.5.3",
89
- "tsdown": "^0.9.1",
90
- "tsdown-jsr-exports-lint": "^0.1.4",
90
+ "tsdown": "^0.10.2",
91
91
  "typescript": "^5.8.3",
92
- "typescript-eslint": "^8.30.1",
93
- "vitest": "^3.1.1"
92
+ "typescript-eslint": "^8.31.1",
93
+ "vitest": "^3.1.2"
94
94
  },
95
95
  "prettier": "@kazupon/prettier-config",
96
96
  "lint-staged": {
@@ -1,116 +0,0 @@
1
- import { ArgToken } from "./parser.d-nUUBO6hL.js";
2
-
3
- //#region src/resolver.d.ts
4
- /**
5
- * An option schema for an argument.
6
- * This schema is similar to the schema of the `node:utils`.
7
- * difference is that:
8
- * - `multiple` property is not supported
9
- * - `required` property and `description` property are added
10
- * - `type` is not only 'string' and 'boolean', but also 'number' and 'enum' too.
11
- * - `default` property type, not support multiple types
12
- */
13
- interface ArgOptionSchema {
14
- /**
15
- * Type of argument.
16
- */
17
- type: "string" | "boolean" | "number" | "enum";
18
- /**
19
- * A single character alias for the option.
20
- */
21
- short?: string;
22
- /**
23
- * A description of the argument.
24
- */
25
- description?: string;
26
- /**
27
- * Whether the argument is required or not.
28
- */
29
- required?: true;
30
- /**
31
- * The allowed values of the argument, and string only. This property is only used when the type is 'enum'.
32
- */
33
- choices?: string[];
34
- /**
35
- * The default value of the argument.
36
- * if the type is 'enum', the default value must be one of the allowed values.
37
- */
38
- default?: string | boolean | number;
39
- }
40
- /**
41
- * An object that contains {@link ArgOptionSchema | options schema}.
42
- */
43
- interface ArgOptions {
44
- [option: string]: ArgOptionSchema;
45
- }
46
- /**
47
- * An object that contains the values of the arguments.
48
- */
49
- type ArgValues<T> = T extends ArgOptions ? ResolveArgValues<T, { [Option in keyof T] : ExtractOptionValue<T[Option]> }> : {
50
- [option: string]: string | boolean | number | undefined
51
- };
52
- /**
53
- * @internal
54
- */
55
- type ExtractOptionValue<O extends ArgOptionSchema> = O["type"] extends "string" ? string : O["type"] extends "boolean" ? boolean : O["type"] extends "number" ? number : O["type"] extends "enum" ? O["choices"] extends string[] ? O["choices"][number] : never : string | boolean | number;
56
- /**
57
- * @internal
58
- */
59
- type ResolveArgValues<
60
- O extends ArgOptions,
61
- V extends Record<keyof O, unknown>
62
- > = { -readonly [Option in keyof O]? : V[Option] } & FilterArgs<O, V, "default"> & FilterArgs<O, V, "required"> extends infer P ? { [K in keyof P] : P[K] } : never;
63
- /**
64
- * @internal
65
- */
66
- type FilterArgs<
67
- O extends ArgOptions,
68
- V extends Record<keyof O, unknown>,
69
- K extends keyof ArgOptionSchema
70
- > = { [Option in keyof O as O[Option][K] extends {} ? Option : never] : V[Option] };
71
- /**
72
- * An options for {@link resolveArgs | resolve arguments}.
73
- */
74
- interface ResolveArgsOptions {
75
- /**
76
- * Whether to group short options.
77
- * @default false
78
- * @see guideline 5 in https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap12.html
79
- */
80
- optionGrouping?: boolean;
81
- /**
82
- * Whether to set the flag value of options prefixed with `--no-` to negative.
83
- * @default false
84
- */
85
- allowNegative?: boolean;
86
- }
87
- /**
88
- * Resolve command line arguments.
89
- * @param options - An options that contains {@link ArgOptionSchema | options schema}.
90
- * @param tokens - An array of {@link ArgToken | tokens}.
91
- * @param resolveArgsOptions - An options that contains {@link resolveArgsOptions | resolve arguments options}.
92
- * @returns An object that contains the values of the arguments, positional arguments, rest arguments, and {@link AggregateError | validation errors}.
93
- */
94
- declare function resolveArgs<T extends ArgOptions>(options: T, tokens: ArgToken[], { optionGrouping, allowNegative }?: ResolveArgsOptions): {
95
- values: ArgValues<T>
96
- positionals: string[]
97
- rest: string[]
98
- error: AggregateError | undefined
99
- };
100
- /**
101
- * An error type for {@link OptionResolveError}.
102
- */
103
- type OptionResolveErrorType = "type" | "required";
104
- /**
105
- * An error that occurs when resolving options.
106
- * This error is thrown when the option is not valid.
107
- */
108
- declare class OptionResolveError extends Error {
109
- name: string;
110
- schema: ArgOptionSchema;
111
- type: OptionResolveErrorType;
112
- constructor(message: string, name: string, type: OptionResolveErrorType, schema: ArgOptionSchema);
113
- }
114
-
115
- //#endregion
116
- export { ArgOptionSchema, ArgOptions, ArgValues, ExtractOptionValue, FilterArgs, OptionResolveError as OptionResolveError$1, OptionResolveErrorType, ResolveArgValues, ResolveArgsOptions, resolveArgs as resolveArgs$1 };