args-tokens 0.9.0 → 0.10.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/README.md +5 -4
- package/lib/parse.d.ts +5 -2
- package/lib/parse.js +1 -2
- package/lib/resolver.d.ts +2 -2
- package/lib/resolver.js +4 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
## ✨ Features
|
|
11
11
|
|
|
12
|
-
- ✅ High performance
|
|
12
|
+
- ✅ High performance
|
|
13
13
|
- ✅ `util.parseArgs` token compatibility
|
|
14
|
-
- ✅
|
|
15
|
-
- ✅
|
|
16
|
-
- ✅
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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,11 +5,9 @@ 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
|
-
* @
|
|
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
|
-
const values = {};
|
|
13
11
|
const positionals = [];
|
|
14
12
|
const longOptionTokens = [];
|
|
15
13
|
const shortOptionTokens = [];
|
|
@@ -110,6 +108,7 @@ export function resolveArgs(options, tokens) {
|
|
|
110
108
|
/**
|
|
111
109
|
* resolve values
|
|
112
110
|
*/
|
|
111
|
+
const values = Object.create(null);
|
|
113
112
|
const errors = [];
|
|
114
113
|
for (const [option, schema] of Object.entries(options)) {
|
|
115
114
|
if (schema.required) {
|
|
@@ -182,11 +181,8 @@ export function resolveArgs(options, tokens) {
|
|
|
182
181
|
values[option] = schema.default;
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
|
-
|
|
186
|
-
|
|
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.
|
|
4
|
+
"version": "0.10.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"knip": "^5.44.4",
|
|
84
84
|
"lint-staged": "^15.4.3",
|
|
85
85
|
"mitata": "^1.0.34",
|
|
86
|
-
"pkg-pr-new": "^0.0.
|
|
86
|
+
"pkg-pr-new": "^0.0.40",
|
|
87
87
|
"prettier": "^3.5.2",
|
|
88
88
|
"typescript": "^5.7.3",
|
|
89
89
|
"typescript-eslint": "^8.24.1",
|