args-tokens 0.9.0 → 0.10.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
@@ -9,11 +9,12 @@
9
9
 
10
10
  ## ✨ Features
11
11
 
12
- - ✅ High performance parser and resolver
12
+ - ✅ High performance
13
13
  - ✅ `util.parseArgs` token compatibility
14
- - ✅ Type safe argument values
15
- - ✅ ES Modules distribution library
16
- - ✅ Support multi runtime: Browser, Node.js, Deno, Bun
14
+ - ✅ ES Modules and modern JavaScript
15
+ - ✅ Type safe
16
+ - ✅ Zero dependencies
17
+ - ✅ Universal runtime
17
18
 
18
19
  ## 🐱 Motivation
19
20
 
package/lib/parse.d.ts CHANGED
@@ -21,6 +21,10 @@ export type ParsedArgs<T extends ArgOptions> = {
21
21
  * Positional arguments, same as `positionals` in {@link resolveArgs}
22
22
  */
23
23
  positionals: string[];
24
+ /**
25
+ * Validation errors, same as `errors` in {@link resolveArgs}
26
+ */
27
+ error: AggregateError | undefined;
24
28
  };
25
29
  /**
26
30
  * Parse command line arguments
@@ -35,7 +39,6 @@ export type ParsedArgs<T extends ArgOptions> = {
35
39
  * ```
36
40
  * @param args - command line arguments
37
41
  * @param options - parse options, about details see {@link ParseOptions}
38
- * @throws if command line arguments are invalid, this function will cause {@link AggregateError | validation errors}.
39
- * @returns parsed values
42
+ * @returns An object that contains the values of the arguments, positional arguments, and {@link AggregateError | validation errors}.
40
43
  */
41
44
  export declare function parse<O extends ArgOptions>(args: string[], options?: ParseOptions<O>): ParsedArgs<O>;
package/lib/parse.js CHANGED
@@ -25,8 +25,7 @@ const DEFAULT_OPTIONS = {
25
25
  * ```
26
26
  * @param args - command line arguments
27
27
  * @param options - parse options, about details see {@link ParseOptions}
28
- * @throws if command line arguments are invalid, this function will cause {@link AggregateError | validation errors}.
29
- * @returns parsed values
28
+ * @returns An object that contains the values of the arguments, positional arguments, and {@link AggregateError | validation errors}.
30
29
  */
31
30
  export function parse(args, options = {}) {
32
31
  const { options: argOptions, allowCompatible = false } = options;
package/lib/resolver.d.ts CHANGED
@@ -47,11 +47,11 @@ type FilterArgs<O extends ArgOptions, V extends Record<keyof O, unknown>, K exte
47
47
  * Resolve command line arguments
48
48
  * @param options - An options that contains {@link ArgOptionSchema | options schema}.
49
49
  * @param tokens - An array of {@link ArgToken | tokens}.
50
- * @throws if command line arguments are invalid, this function will cause {@link AggregateError | validation errors}.
51
- * @returns An object that contains the values of the arguments and positional arguments.
50
+ * @returns An object that contains the values of the arguments, positional arguments, and {@link AggregateError | validation errors}.
52
51
  */
53
52
  export declare function resolveArgs<T extends ArgOptions>(options: T, tokens: ArgToken[]): {
54
53
  values: ArgValues<T>;
55
54
  positionals: string[];
55
+ error: AggregateError | undefined;
56
56
  };
57
57
  export {};
package/lib/resolver.js CHANGED
@@ -5,8 +5,7 @@ import { hasLongOptionPrefix, isShortOption } from './parser.js';
5
5
  * Resolve command line arguments
6
6
  * @param options - An options that contains {@link ArgOptionSchema | options schema}.
7
7
  * @param tokens - An array of {@link ArgToken | tokens}.
8
- * @throws if command line arguments are invalid, this function will cause {@link AggregateError | validation errors}.
9
- * @returns An object that contains the values of the arguments and positional arguments.
8
+ * @returns An object that contains the values of the arguments, positional arguments, and {@link AggregateError | validation errors}.
10
9
  */
11
10
  export function resolveArgs(options, tokens) {
12
11
  const values = {};
@@ -182,11 +181,8 @@ export function resolveArgs(options, tokens) {
182
181
  values[option] = schema.default;
183
182
  }
184
183
  }
185
- if (errors.length > 0) {
186
- // eslint-disable-next-line unicorn/error-message
187
- throw new AggregateError(errors);
188
- }
189
- return { values, positionals };
184
+ // eslint-disable-next-line unicorn/error-message
185
+ return { values, positionals, error: errors.length > 0 ? new AggregateError(errors) : undefined };
190
186
  }
191
187
  function createRequireError(option, schema) {
192
188
  return new Error(`Option '--${option}' ${schema.short ? `or '-${schema.short}'` : ''} is required`);
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.9.0",
4
+ "version": "0.10.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"