args-tokens 0.13.2 → 0.13.4

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
@@ -4,34 +4,34 @@ import { ArgOptions, ArgValues } from './resolver.js';
4
4
  export { ArgOptionSchema, OptionResolveError, resolveArgs } from './resolver.js';
5
5
 
6
6
  /**
7
- * Parse options for {@link parse} function
7
+ * Parse options for {@link parse} function.
8
8
  */
9
9
  interface ParseOptions<O extends ArgOptions> extends ParserOptions {
10
10
  /**
11
- * Command line options, about details see {@link ArgOptions}
11
+ * Command line options, about details see {@link ArgOptions}.
12
12
  */
13
13
  options?: O;
14
14
  }
15
15
  /**
16
- * Parsed command line arguments
16
+ * Parsed command line arguments.
17
17
  */
18
18
  type ParsedArgs<T extends ArgOptions> = {
19
19
  /**
20
- * Parsed values, same as `values` in {@link resolveArgs}
20
+ * Parsed values, same as `values` in {@link resolveArgs}.
21
21
  */
22
22
  values: ArgValues<T>
23
23
  /**
24
- * Positional arguments, same as `positionals` in {@link resolveArgs}
24
+ * Positional arguments, same as `positionals` in {@link resolveArgs}.
25
25
  */
26
26
  positionals: string[]
27
27
  /**
28
- * Validation errors, same as `errors` in {@link resolveArgs}
28
+ * Validation errors, same as `errors` in {@link resolveArgs}.
29
29
  */
30
30
  error: AggregateError | undefined
31
31
  };
32
32
  /**
33
- * Parse command line arguments
34
- * @description This function is a convenient API, that is used {@link parseArgs} and {@link resolveArgs} in internal.
33
+ * Parse command line arguments.
34
+ * This function is a convenient API, that is used {@link parseArgs} and {@link resolveArgs} in internal.
35
35
  * @example
36
36
  * ```js
37
37
  * import { parse } from 'args-tokens'
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { parseArgs } from "./parser-DYj8MxIm.js";
2
- import { OptionResolveError, resolveArgs } from "./resolver-DcIzyGlA.js";
1
+ import { parseArgs } from "./parser-DxH6Mf-o.js";
2
+ import { OptionResolveError, resolveArgs } from "./resolver-Di82Qgwx.js";
3
3
 
4
4
  //#region src/parse.ts
5
5
  const DEFAULT_OPTIONS = {
@@ -124,9 +124,9 @@ function isShortOption(arg) {
124
124
  return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
125
125
  }
126
126
  /**
127
- * Check if `arg` is a short option group (e.g. `-abc`)
127
+ * Check if `arg` is a short option group (e.g. `-abc`).
128
128
  * @param arg the argument to check
129
- * @returns whether `arg` is a short option group
129
+ * @returns whether `arg` is a short option group.
130
130
  */
131
131
  function isShortOptionGroup(arg) {
132
132
  if (arg.length <= 2) return false;
@@ -135,17 +135,17 @@ function isShortOptionGroup(arg) {
135
135
  return true;
136
136
  }
137
137
  /**
138
- * Check if `arg` is a long option (e.g. `--foo`)
138
+ * Check if `arg` is a long option (e.g. `--foo`).
139
139
  * @param arg the argument to check
140
- * @returns whether `arg` is a long option
140
+ * @returns whether `arg` is a long option.
141
141
  */
142
142
  function isLongOption(arg) {
143
143
  return hasLongOptionPrefix(arg) && !arg.includes(EQUAL_CHAR, 3);
144
144
  }
145
145
  /**
146
- * Check if `arg` is a long option with value (e.g. `--foo=bar`)
146
+ * Check if `arg` is a long option with value (e.g. `--foo=bar`).
147
147
  * @param arg the argument to check
148
- * @returns whether `arg` is a long option
148
+ * @returns whether `arg` is a long option.
149
149
  */
150
150
  function isLongOptionAndValue(arg) {
151
151
  return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
@@ -154,9 +154,9 @@ function hasLongOptionPrefix(arg) {
154
154
  return arg.length > 2 && ~arg.indexOf(LONG_OPTION_PREFIX);
155
155
  }
156
156
  /**
157
- * Check if a `value` is an option value
157
+ * Check if a `value` is an option value.
158
158
  * @param value a value to check
159
- * @returns whether a `value` is an option value
159
+ * @returns whether a `value` is an option value.
160
160
  */
161
161
  function hasOptionValue(value) {
162
162
  return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
package/lib/parser.d.ts CHANGED
@@ -1,28 +1,32 @@
1
1
  /**
2
- * Argument token Kind
2
+ * Entry point of argument parser.
3
+ * @module
4
+ */
5
+ /**
6
+ * Argument token Kind.
3
7
  * - `option`: option token, support short option (e.g. `-x`) and long option (e.g. `--foo`)
4
8
  * - `option-terminator`: option terminator (`--`) token, see guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
5
9
  * - `positional`: positional token
6
10
  */
7
11
  type ArgTokenKind = "option" | "option-terminator" | "positional";
8
12
  /**
9
- * Argument token
13
+ * Argument token.
10
14
  */
11
15
  interface ArgToken {
12
16
  /**
13
- * Argument token kind
17
+ * Argument token kind.
14
18
  */
15
19
  kind: ArgTokenKind;
16
20
  /**
17
- * Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1
21
+ * Argument token index, e.g `--foo bar` => `--foo` index is 0, `bar` index is 1.
18
22
  */
19
23
  index: number;
20
24
  /**
21
- * Option name, e.g. `--foo` => `foo`, `-x` => `x`
25
+ * Option name, e.g. `--foo` => `foo`, `-x` => `x`.
22
26
  */
23
27
  name?: string;
24
28
  /**
25
- * Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`
29
+ * Raw option name, e.g. `--foo` => `--foo`, `-x` => `-x`.
26
30
  */
27
31
  rawName?: string;
28
32
  /**
@@ -36,17 +40,17 @@ interface ArgToken {
36
40
  inlineValue?: boolean;
37
41
  }
38
42
  /**
39
- * Parser Options
43
+ * Parser Options.
40
44
  */
41
45
  interface ParserOptions {
42
46
  /**
43
- * [Node.js parseArgs](https://nodejs.org/api/util.html#parseargs-tokens) tokens compatible mode
47
+ * [Node.js parseArgs](https://nodejs.org/api/util.html#parseargs-tokens) tokens compatible mode.
44
48
  * @default false
45
49
  */
46
50
  allowCompatible?: boolean;
47
51
  }
48
52
  /**
49
- * Parse command line arguments
53
+ * Parse command line arguments.
50
54
  * @example
51
55
  * ```js
52
56
  * import { parseArgs } from 'args-tokens' // for Node.js and Bun
@@ -59,19 +63,19 @@ interface ParserOptions {
59
63
  * ```
60
64
  * @param args command line arguments
61
65
  * @param options parse options
62
- * @returns argument tokens
66
+ * @returns Argument tokens.
63
67
  */
64
68
  declare function parseArgs(args: string[], options?: ParserOptions): ArgToken[];
65
69
  /**
66
- * Check if `arg` is a short option (e.g. `-f`)
70
+ * Check if `arg` is a short option (e.g. `-f`).
67
71
  * @param arg the argument to check
68
- * @returns whether `arg` is a short option
72
+ * @returns whether `arg` is a short option.
69
73
  */
70
74
  declare function isShortOption(arg: string): boolean;
71
75
  /**
72
- * Check if `arg` is a long option prefix (e.g. `--`)
76
+ * Check if `arg` is a long option prefix (e.g. `--`).
73
77
  * @param arg the argument to check
74
- * @returns whether `arg` is a long option prefix
78
+ * @returns whether `arg` is a long option prefix.
75
79
  */
76
80
  declare function hasLongOptionPrefix(arg: string): boolean;
77
81
 
package/lib/parser.js CHANGED
@@ -1,3 +1,3 @@
1
- import { hasLongOptionPrefix, isShortOption, parseArgs } from "./parser-DYj8MxIm.js";
1
+ import { hasLongOptionPrefix, isShortOption, parseArgs } from "./parser-DxH6Mf-o.js";
2
2
 
3
3
  export { hasLongOptionPrefix, isShortOption, parseArgs };
@@ -1,4 +1,4 @@
1
- import { hasLongOptionPrefix, isShortOption } from "./parser-DYj8MxIm.js";
1
+ import { hasLongOptionPrefix, isShortOption } from "./parser-DxH6Mf-o.js";
2
2
 
3
3
  //#region src/resolver.ts
4
4
  function resolveArgs(options, tokens) {
package/lib/resolver.d.ts CHANGED
@@ -2,8 +2,7 @@ import { ArgToken } from './parser.js';
2
2
 
3
3
  /**
4
4
  * An option schema for an argument.
5
- *
6
- * @description This schema is similar to the schema of the `node:utils`.
5
+ * This schema is similar to the schema of the `node:utils`.
7
6
  * difference is that:
8
7
  * - `multiple` property is not supported
9
8
  * - `required` property and `description` property are added
@@ -54,7 +53,7 @@ type FilterArgs<
54
53
  K extends keyof ArgOptionSchema
55
54
  > = { [Option in keyof O as O[Option][K] extends {} ? Option : never] : V[Option] };
56
55
  /**
57
- * Resolve command line arguments
56
+ * Resolve command line arguments.
58
57
  * @param options - An options that contains {@link ArgOptionSchema | options schema}.
59
58
  * @param tokens - An array of {@link ArgToken | tokens}.
60
59
  * @returns An object that contains the values of the arguments, positional arguments, and {@link AggregateError | validation errors}.
@@ -64,6 +63,10 @@ declare function resolveArgs<T extends ArgOptions>(options: T, tokens: ArgToken[
64
63
  positionals: string[]
65
64
  error: AggregateError | undefined
66
65
  };
66
+ /**
67
+ * An error that occurs when resolving options.
68
+ * This error is thrown when the option is not valid.
69
+ */
67
70
  declare class OptionResolveError extends Error {
68
71
  name: string;
69
72
  schema: ArgOptionSchema;
package/lib/resolver.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./parser-DYj8MxIm.js";
2
- import { OptionResolveError, resolveArgs } from "./resolver-DcIzyGlA.js";
1
+ import "./parser-DxH6Mf-o.js";
2
+ import { OptionResolveError, resolveArgs } from "./resolver-Di82Qgwx.js";
3
3
 
4
4
  export { OptionResolveError, 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.13.2",
4
+ "version": "0.13.4",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"