args-tokens 0.2.4 → 0.2.5
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/cjs/index.d.ts +39 -2
- package/lib/cjs/index.js +10 -0
- package/lib/esm/index.d.ts +39 -2
- package/lib/esm/index.js +10 -0
- package/package.json +1 -1
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Argument token Kind
|
|
3
|
+
* - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
|
|
4
|
+
* - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
|
5
|
+
* - `positional`: positional token
|
|
6
|
+
*/
|
|
7
|
+
export type ArgTokenKind = 'option' | 'option-terminator' | 'positional';
|
|
8
|
+
/**
|
|
9
|
+
* Argument token
|
|
10
|
+
*/
|
|
2
11
|
export interface ArgToken {
|
|
12
|
+
/**
|
|
13
|
+
* Argument token kind
|
|
14
|
+
*/
|
|
3
15
|
kind: ArgTokenKind;
|
|
16
|
+
/**
|
|
17
|
+
* Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1
|
|
18
|
+
*/
|
|
4
19
|
index: number;
|
|
20
|
+
/**
|
|
21
|
+
* Option name, e.g. `--foo` => `foo`, `-x` => `x`
|
|
22
|
+
*/
|
|
5
23
|
name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`
|
|
26
|
+
*/
|
|
6
27
|
rawName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Option value, e.g. `--foo=bar` => `bar`, `-x=bar` => `bar`.
|
|
30
|
+
* If the `allowCompatible` option is `true`, short option value will be same as Node.js `parseArgs` behavior.
|
|
31
|
+
*/
|
|
7
32
|
value?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
|
|
35
|
+
*/
|
|
8
36
|
inlineValue?: boolean;
|
|
9
37
|
}
|
|
10
38
|
/**
|
|
@@ -19,9 +47,18 @@ export interface ParseOptions {
|
|
|
19
47
|
}
|
|
20
48
|
/**
|
|
21
49
|
* Parse command line arguments
|
|
50
|
+
* @example
|
|
51
|
+
* ```js
|
|
52
|
+
* import { parseArgs } from 'args-tokens' // for Node.js and Bun
|
|
53
|
+
* // import { parseArgs } from 'jsr:@kazupon/args-tokens' // for Deno
|
|
54
|
+
*
|
|
55
|
+
* const tokens = parseArgs(['--foo', 'bar', '-x', '--bar=baz'])
|
|
56
|
+
* // do something with using tokens
|
|
57
|
+
* // ...
|
|
58
|
+
* console.log('tokens:', tokens)
|
|
59
|
+
* ```
|
|
22
60
|
* @param args command line arguments
|
|
23
61
|
* @param options parse options
|
|
24
62
|
* @returns argument tokens
|
|
25
63
|
*/
|
|
26
64
|
export declare function parseArgs(args: string[], options?: ParseOptions): ArgToken[];
|
|
27
|
-
export {};
|
package/lib/cjs/index.js
CHANGED
|
@@ -16,6 +16,16 @@ const SHORT_OPTION_PREFIX = HYPHEN_CHAR;
|
|
|
16
16
|
const LONG_OPTION_PREFIX = '--';
|
|
17
17
|
/**
|
|
18
18
|
* Parse command line arguments
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* import { parseArgs } from 'args-tokens' // for Node.js and Bun
|
|
22
|
+
* // import { parseArgs } from 'jsr:@kazupon/args-tokens' // for Deno
|
|
23
|
+
*
|
|
24
|
+
* const tokens = parseArgs(['--foo', 'bar', '-x', '--bar=baz'])
|
|
25
|
+
* // do something with using tokens
|
|
26
|
+
* // ...
|
|
27
|
+
* console.log('tokens:', tokens)
|
|
28
|
+
* ```
|
|
19
29
|
* @param args command line arguments
|
|
20
30
|
* @param options parse options
|
|
21
31
|
* @returns argument tokens
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Argument token Kind
|
|
3
|
+
* - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
|
|
4
|
+
* - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
|
5
|
+
* - `positional`: positional token
|
|
6
|
+
*/
|
|
7
|
+
export type ArgTokenKind = 'option' | 'option-terminator' | 'positional';
|
|
8
|
+
/**
|
|
9
|
+
* Argument token
|
|
10
|
+
*/
|
|
2
11
|
export interface ArgToken {
|
|
12
|
+
/**
|
|
13
|
+
* Argument token kind
|
|
14
|
+
*/
|
|
3
15
|
kind: ArgTokenKind;
|
|
16
|
+
/**
|
|
17
|
+
* Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1
|
|
18
|
+
*/
|
|
4
19
|
index: number;
|
|
20
|
+
/**
|
|
21
|
+
* Option name, e.g. `--foo` => `foo`, `-x` => `x`
|
|
22
|
+
*/
|
|
5
23
|
name?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`
|
|
26
|
+
*/
|
|
6
27
|
rawName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Option value, e.g. `--foo=bar` => `bar`, `-x=bar` => `bar`.
|
|
30
|
+
* If the `allowCompatible` option is `true`, short option value will be same as Node.js `parseArgs` behavior.
|
|
31
|
+
*/
|
|
7
32
|
value?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
|
|
35
|
+
*/
|
|
8
36
|
inlineValue?: boolean;
|
|
9
37
|
}
|
|
10
38
|
/**
|
|
@@ -19,9 +47,18 @@ export interface ParseOptions {
|
|
|
19
47
|
}
|
|
20
48
|
/**
|
|
21
49
|
* Parse command line arguments
|
|
50
|
+
* @example
|
|
51
|
+
* ```js
|
|
52
|
+
* import { parseArgs } from 'args-tokens' // for Node.js and Bun
|
|
53
|
+
* // import { parseArgs } from 'jsr:@kazupon/args-tokens' // for Deno
|
|
54
|
+
*
|
|
55
|
+
* const tokens = parseArgs(['--foo', 'bar', '-x', '--bar=baz'])
|
|
56
|
+
* // do something with using tokens
|
|
57
|
+
* // ...
|
|
58
|
+
* console.log('tokens:', tokens)
|
|
59
|
+
* ```
|
|
22
60
|
* @param args command line arguments
|
|
23
61
|
* @param options parse options
|
|
24
62
|
* @returns argument tokens
|
|
25
63
|
*/
|
|
26
64
|
export declare function parseArgs(args: string[], options?: ParseOptions): ArgToken[];
|
|
27
|
-
export {};
|
package/lib/esm/index.js
CHANGED
|
@@ -13,6 +13,16 @@ const SHORT_OPTION_PREFIX = HYPHEN_CHAR;
|
|
|
13
13
|
const LONG_OPTION_PREFIX = '--';
|
|
14
14
|
/**
|
|
15
15
|
* Parse command line arguments
|
|
16
|
+
* @example
|
|
17
|
+
* ```js
|
|
18
|
+
* import { parseArgs } from 'args-tokens' // for Node.js and Bun
|
|
19
|
+
* // import { parseArgs } from 'jsr:@kazupon/args-tokens' // for Deno
|
|
20
|
+
*
|
|
21
|
+
* const tokens = parseArgs(['--foo', 'bar', '-x', '--bar=baz'])
|
|
22
|
+
* // do something with using tokens
|
|
23
|
+
* // ...
|
|
24
|
+
* console.log('tokens:', tokens)
|
|
25
|
+
* ```
|
|
16
26
|
* @param args command line arguments
|
|
17
27
|
* @param options parse options
|
|
18
28
|
* @returns argument tokens
|