args-tokens 0.10.2 → 0.11.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/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  With [mitata](https://github.com/evanwashere/mitata):
27
27
 
28
- ```
28
+ ```sh
29
29
  pnpm bench:mitata
30
30
 
31
31
  > args-tokens@0.0.0 bench:mitata /path/to/projects/args-tokens
@@ -63,7 +63,7 @@ args-tokens parse (equivalent to util.parseArgs) ┤■■■■■■■■■
63
63
 
64
64
  With [vitest](https://vitest.dev/guide/features.html#benchmarking):
65
65
 
66
- ```
66
+ ```sh
67
67
  pnpm bench:vitest
68
68
 
69
69
  > args-tokens@0.0.0 bench:vitest /path/to/projects/args-tokens
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { parse } from './parse.js';
2
2
  export { parseArgs } from './parser.js';
3
- export { resolveArgs } from './resolver.js';
3
+ export { OptionResolveError, resolveArgs } from './resolver.js';
4
4
  export type { ParsedArgs, ParseOptions } from './parse';
5
5
  export type { ArgToken, ParserOptions } from './parser';
6
6
  export type { ArgOptions, ArgOptionSchema, ArgValues } from './resolver';
package/lib/index.js CHANGED
@@ -2,4 +2,4 @@
2
2
  // Modifier: kazuya kawaguchi (a.k.a. kazupon)
3
3
  export { parse } from './parse.js';
4
4
  export { parseArgs } from './parser.js';
5
- export { resolveArgs } from './resolver.js';
5
+ export { OptionResolveError, resolveArgs } from './resolver.js';
package/lib/resolver.d.ts CHANGED
@@ -54,4 +54,9 @@ export declare function resolveArgs<T extends ArgOptions>(options: T, tokens: Ar
54
54
  positionals: string[];
55
55
  error: AggregateError | undefined;
56
56
  };
57
+ export declare class OptionResolveError extends Error {
58
+ name: string;
59
+ schema: ArgOptionSchema;
60
+ constructor(message: string, name: string, schema: ArgOptionSchema);
61
+ }
57
62
  export {};
package/lib/resolver.js CHANGED
@@ -140,7 +140,7 @@ export function resolveArgs(options, tokens) {
140
140
  continue;
141
141
  }
142
142
  }
143
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
144
  ;
145
145
  values[option] = resolveOptionValue(token, schema);
146
146
  continue;
@@ -167,7 +167,7 @@ export function resolveArgs(options, tokens) {
167
167
  continue;
168
168
  }
169
169
  }
170
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
171
  ;
172
172
  values[option] = resolveOptionValue(token, schema);
173
173
  continue;
@@ -176,7 +176,7 @@ export function resolveArgs(options, tokens) {
176
176
  // eslint-disable-next-line unicorn/no-null
177
177
  if (values[option] == null && schema.default != null) {
178
178
  // check if the default value is in values
179
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
180
  ;
181
181
  values[option] = schema.default;
182
182
  }
@@ -185,7 +185,16 @@ export function resolveArgs(options, tokens) {
185
185
  return { values, positionals, error: errors.length > 0 ? new AggregateError(errors) : undefined };
186
186
  }
187
187
  function createRequireError(option, schema) {
188
- return new Error(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ''}is required`);
188
+ return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ''}is required`, option, schema);
189
+ }
190
+ export class OptionResolveError extends Error {
191
+ name;
192
+ schema;
193
+ constructor(message, name, schema) {
194
+ super(message);
195
+ this.name = name;
196
+ this.schema = schema;
197
+ }
189
198
  }
190
199
  function validateRequire(token, option, schema) {
191
200
  if (schema.required && schema.type !== 'boolean' && !token.value) {
@@ -214,7 +223,7 @@ function isNumeric(str) {
214
223
  return str.trim() !== '' && !isNaN(str);
215
224
  }
216
225
  function createTypeError(option, schema) {
217
- return new TypeError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ''}should be '${schema.type}'`);
226
+ return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ''}should be '${schema.type}'`, option, schema);
218
227
  }
219
228
  function resolveOptionValue(token, schema) {
220
229
  if (token.value) {
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.10.2",
4
+ "version": "0.11.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -65,29 +65,29 @@
65
65
  }
66
66
  },
67
67
  "devDependencies": {
68
- "@eslint/markdown": "^6.2.2",
69
- "@kazupon/eslint-config": "^0.22.0",
68
+ "@eslint/markdown": "^6.3.0",
69
+ "@kazupon/eslint-config": "^0.26.0",
70
70
  "@kazupon/prettier-config": "^0.1.1",
71
- "@types/node": "^22.13.9",
72
- "@vitest/eslint-plugin": "^1.1.36",
73
- "bumpp": "^10.0.3",
74
- "eslint": "^9.21.0",
75
- "eslint-config-prettier": "^10.0.2",
76
- "eslint-plugin-jsonc": "^2.19.1",
71
+ "@types/node": "^22.13.14",
72
+ "@vitest/eslint-plugin": "^1.1.38",
73
+ "bumpp": "^10.1.0",
74
+ "eslint": "^9.23.0",
75
+ "eslint-config-prettier": "^10.1.1",
76
+ "eslint-plugin-jsonc": "^2.20.0",
77
77
  "eslint-plugin-promise": "^7.2.1",
78
78
  "eslint-plugin-regexp": "^2.7.0",
79
- "eslint-plugin-unicorn": "^57.0.0",
79
+ "eslint-plugin-unicorn": "^58.0.0",
80
80
  "eslint-plugin-yml": "^1.17.0",
81
81
  "gh-changelogen": "^0.2.8",
82
82
  "jsr": "^0.13.4",
83
- "knip": "^5.45.0",
84
- "lint-staged": "^15.4.3",
83
+ "knip": "^5.46.2",
84
+ "lint-staged": "^15.5.0",
85
85
  "mitata": "^1.0.34",
86
- "pkg-pr-new": "^0.0.40",
86
+ "pkg-pr-new": "^0.0.41",
87
87
  "prettier": "^3.5.3",
88
88
  "typescript": "^5.8.2",
89
- "typescript-eslint": "^8.26.0",
90
- "vitest": "^3.0.7"
89
+ "typescript-eslint": "^8.28.0",
90
+ "vitest": "^3.0.9"
91
91
  },
92
92
  "prettier": "@kazupon/prettier-config",
93
93
  "lint-staged": {