args-tokens 0.17.1 → 0.18.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.
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ArgToken, ParserOptions, parseArgs$1 as parseArgs } from "./parser-Bx112mWZ.js";
2
- import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver--lXziDSy.js";
2
+ import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-D_oOCXlX.js";
3
3
 
4
4
  //#region src/parse.d.ts
5
5
  /**
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { parseArgs } from "./parser-Dr4iAGaX.js";
2
- import { ArgResolveError, resolveArgs } from "./resolver-DuUwC6Fy.js";
2
+ import { ArgResolveError, resolveArgs } from "./resolver-_BCsM-y_.js";
3
3
 
4
4
  //#region src/parse.ts
5
5
  const DEFAULT_OPTIONS = {
@@ -5,7 +5,6 @@ import { ArgToken } from "./parser-Bx112mWZ.js";
5
5
  * An argument schema
6
6
  * This schema is similar to the schema of the `node:utils`.
7
7
  * difference is that:
8
- * - `multiple` property is not supported
9
8
  * - `required` property and `description` property are added
10
9
  * - `type` is not only 'string' and 'boolean', but also 'number', 'enum' and 'positional' too.
11
10
  * - `default` property type, not support multiple types
@@ -14,7 +13,6 @@ import { ArgToken } from "./parser-Bx112mWZ.js";
14
13
  * An argument schema
15
14
  * This schema is similar to the schema of the `node:utils`.
16
15
  * difference is that:
17
- * - `multiple` property is not supported
18
16
  * - `required` property and `description` property are added
19
17
  * - `type` is not only 'string' and 'boolean', but also 'number', 'enum' and 'positional' too.
20
18
  * - `default` property type, not support multiple types
@@ -37,6 +35,10 @@ interface ArgSchema {
37
35
  */
38
36
  required?: true;
39
37
  /**
38
+ * Whether the argument allow multiple values or not.
39
+ */
40
+ multiple?: true;
41
+ /**
40
42
  * Whether the negatable option for `boolean` type
41
43
  */
42
44
  negatable?: boolean;
@@ -60,12 +62,13 @@ interface Args {
60
62
  * An object that contains the values of the arguments.
61
63
  */
62
64
  type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
63
- [option: string]: string | boolean | number | undefined;
65
+ [option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
64
66
  };
65
67
  /**
66
68
  * @internal
67
69
  */
68
- type ExtractOptionValue<A extends ArgSchema> = A["type"] extends "string" ? string : A["type"] extends "boolean" ? boolean : A["type"] extends "number" ? number : A["type"] extends "positional" ? string : A["type"] extends "enum" ? A["choices"] extends string[] | readonly string[] ? A["choices"][number] : never : string | boolean | number;
70
+ type ExtractOptionValue<A extends ArgSchema> = A["type"] extends "string" ? ResolveOptionValue<A, string> : A["type"] extends "boolean" ? ResolveOptionValue<A, boolean> : A["type"] extends "number" ? ResolveOptionValue<A, number> : A["type"] extends "positional" ? ResolveOptionValue<A, string> : A["type"] extends "enum" ? A["choices"] extends string[] | readonly string[] ? ResolveOptionValue<A, A["choices"][number]> : never : ResolveOptionValue<A, string | boolean | number>;
71
+ type ResolveOptionValue<A extends ArgSchema, T> = A["multiple"] extends true ? T[] : T;
69
72
  /**
70
73
  * @internal
71
74
  */
@@ -12,8 +12,7 @@ const SKIP_POSITIONAL_DEFAULT = -1;
12
12
  function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT } = {}) {
13
13
  const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
14
14
  const rest = [];
15
- const longOptionTokens = [];
16
- const shortOptionTokens = [];
15
+ const optionTokens = [];
17
16
  const positionalTokens = [];
18
17
  let currentLongOption;
19
18
  let currentShortOption;
@@ -29,14 +28,14 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
29
28
  function applyLongOptionValue(value = void 0) {
30
29
  if (currentLongOption) {
31
30
  currentLongOption.value = value;
32
- longOptionTokens.push({ ...currentLongOption });
31
+ optionTokens.push({ ...currentLongOption });
33
32
  currentLongOption = void 0;
34
33
  }
35
34
  }
36
35
  function applyShortOptionValue(value = void 0) {
37
36
  if (currentShortOption) {
38
37
  currentShortOption.value = value || toShortValue();
39
- shortOptionTokens.push({ ...currentShortOption });
38
+ optionTokens.push({ ...currentShortOption });
40
39
  currentShortOption = void 0;
41
40
  }
42
41
  }
@@ -65,18 +64,18 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
65
64
  } else if (token.kind === "option") if (token.rawName) {
66
65
  if (hasLongOptionPrefix(token.rawName)) {
67
66
  applyLongOptionValue();
68
- if (token.inlineValue) longOptionTokens.push({ ...token });
67
+ if (token.inlineValue) optionTokens.push({ ...token });
69
68
  else currentLongOption = { ...token };
70
69
  applyShortOptionValue();
71
70
  } else if (isShortOption(token.rawName)) if (currentShortOption) {
72
71
  if (currentShortOption.index === token.index) if (optionGrouping) {
73
72
  currentShortOption.value = token.value;
74
- shortOptionTokens.push({ ...currentShortOption });
73
+ optionTokens.push({ ...currentShortOption });
75
74
  currentShortOption = { ...token };
76
75
  } else expandableShortOptions.push({ ...token });
77
76
  else {
78
77
  currentShortOption.value = toShortValue();
79
- shortOptionTokens.push({ ...currentShortOption });
78
+ optionTokens.push({ ...currentShortOption });
80
79
  currentShortOption = { ...token };
81
80
  }
82
81
  applyLongOptionValue();
@@ -87,7 +86,7 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
87
86
  } else {
88
87
  if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
89
88
  currentShortOption.value = token.value;
90
- shortOptionTokens.push({ ...currentShortOption });
89
+ optionTokens.push({ ...currentShortOption });
91
90
  currentShortOption = void 0;
92
91
  }
93
92
  applyLongOptionValue();
@@ -118,7 +117,9 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
118
117
  let positionalsCount = 0;
119
118
  for (const [option, schema] of Object.entries(args)) {
120
119
  if (schema.required) {
121
- const found = longOptionTokens.find((token) => token.name === option) || schema.short && shortOptionTokens.find((token) => token.name === schema.short);
120
+ const found = optionTokens.find((token) => {
121
+ return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === option;
122
+ });
122
123
  if (!found) {
123
124
  errors.push(createRequireError(option, schema));
124
125
  continue;
@@ -132,9 +133,9 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
132
133
  positionalsCount++;
133
134
  continue;
134
135
  }
135
- for (let i = 0; i < longOptionTokens.length; i++) {
136
- const token = longOptionTokens[i];
137
- if (checkTokenName(option, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName)) {
136
+ for (let i = 0; i < optionTokens.length; i++) {
137
+ const token = optionTokens[i];
138
+ if (checkTokenName(option, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
138
139
  const invalid = validateRequire(token, option, schema);
139
140
  if (invalid) {
140
141
  errors.push(invalid);
@@ -148,27 +149,10 @@ function resolveArgs(args, tokens, { optionGrouping = false, skipPositional = SK
148
149
  continue;
149
150
  }
150
151
  }
151
- values[option] = resolveArgumentValue(token, schema);
152
- continue;
153
- }
154
- }
155
- for (let i = 0; i < shortOptionTokens.length; i++) {
156
- const token = shortOptionTokens[i];
157
- if (schema.short === token.name && token.rawName != null && isShortOption(token.rawName)) {
158
- const invalid = validateRequire(token, option, schema);
159
- if (invalid) {
160
- errors.push(invalid);
161
- continue;
162
- }
163
- if (schema.type === "boolean") token.value = void 0;
164
- else {
165
- const invalid$1 = validateValue(token, option, schema);
166
- if (invalid$1) {
167
- errors.push(invalid$1);
168
- continue;
169
- }
170
- }
171
- values[option] = resolveArgumentValue(token, schema);
152
+ if (schema.multiple) {
153
+ values[option] ||= [];
154
+ values[option].push(resolveArgumentValue(token, schema));
155
+ } else values[option] = resolveArgumentValue(token, schema);
172
156
  continue;
173
157
  }
174
158
  }
package/lib/resolver.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./parser-Bx112mWZ.js";
2
- import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, ResolveArgValues, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver--lXziDSy.js";
2
+ import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, ResolveArgValues, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-D_oOCXlX.js";
3
3
  export { ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, ResolveArgValues, ResolveArgs, resolveArgs };
package/lib/resolver.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./parser-Dr4iAGaX.js";
2
- import { ArgResolveError, resolveArgs } from "./resolver-DuUwC6Fy.js";
2
+ import { ArgResolveError, resolveArgs } from "./resolver-_BCsM-y_.js";
3
3
 
4
4
  export { ArgResolveError, 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.17.1",
4
+ "version": "0.18.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -68,29 +68,30 @@
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.15.3",
72
- "@vitest/eslint-plugin": "^1.1.44",
73
- "bumpp": "^10.1.0",
74
- "deno": "^2.3.1",
75
- "eslint": "^9.26.0",
76
- "eslint-config-prettier": "^10.1.2",
77
- "eslint-plugin-jsonc": "^2.20.0",
71
+ "@types/node": "^22.15.21",
72
+ "@typescript/native-preview": "7.0.0-dev.20250522.2",
73
+ "@vitest/eslint-plugin": "^1.2.0",
74
+ "bumpp": "^10.1.1",
75
+ "deno": "^2.3.3",
76
+ "eslint": "^9.27.0",
77
+ "eslint-config-prettier": "^10.1.5",
78
+ "eslint-plugin-jsonc": "^2.20.1",
78
79
  "eslint-plugin-promise": "^7.2.1",
79
80
  "eslint-plugin-regexp": "^2.7.0",
80
- "eslint-plugin-unicorn": "^59.0.0",
81
+ "eslint-plugin-unicorn": "^59.0.1",
81
82
  "eslint-plugin-yml": "^1.18.0",
82
83
  "gh-changelogen": "^0.2.8",
83
84
  "jsr": "^0.13.4",
84
- "jsr-exports-lint": "^0.2.0",
85
- "knip": "^5.52.0",
86
- "lint-staged": "^15.5.1",
85
+ "jsr-exports-lint": "^0.4.0",
86
+ "knip": "^5.57.1",
87
+ "lint-staged": "^15.5.2",
87
88
  "mitata": "^1.0.34",
88
- "pkg-pr-new": "^0.0.43",
89
+ "pkg-pr-new": "^0.0.50",
89
90
  "prettier": "^3.5.3",
90
- "tsdown": "^0.10.2",
91
+ "tsdown": "^0.12.1",
91
92
  "typescript": "^5.8.3",
92
- "typescript-eslint": "^8.31.1",
93
- "vitest": "^3.1.2"
93
+ "typescript-eslint": "^8.32.1",
94
+ "vitest": "^3.1.4"
94
95
  },
95
96
  "prettier": "@kazupon/prettier-config",
96
97
  "lint-staged": {
@@ -126,6 +127,6 @@
126
127
  "test": "vitest run",
127
128
  "typecheck": "pnpm run --parallel --color \"/^typecheck:/\"",
128
129
  "typecheck:deno": "deno check src",
129
- "typecheck:tsc": "tsc --noEmit"
130
+ "typecheck:tsc": "tsgo --noEmit"
130
131
  }
131
132
  }