args-tokens 0.20.0 → 0.21.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
@@ -319,7 +319,7 @@ The development of Gunish is supported by my OSS sponsors!
319
319
 
320
320
  <p align="center">
321
321
  <a href="https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg">
322
- <img src='https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg'/>
322
+ <img alt="sponsor src='https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg'/>
323
323
  </a>
324
324
  </p>
325
325
 
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ArgToken, ParserOptions, parseArgs$1 as parseArgs } from "./parser-FiQIAw-2.js";
2
- import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-U72Jg6Ll.js";
2
+ import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExplicitlyProvided, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-C87QZIMT.js";
3
3
 
4
4
  //#region src/parse.d.ts
5
5
 
@@ -36,6 +36,11 @@ type ParsedArgs<A extends Args> = {
36
36
  * Argument tokens, same as `tokens` which is parsed by {@link parseArgs}.
37
37
  */
38
38
  tokens: ArgToken[];
39
+ /**
40
+ * Explicit provision status, same as `explicit` in {@link resolveArgs}.
41
+ * Indicates which arguments were explicitly provided vs using default values.
42
+ */
43
+ explicit: ExplicitlyProvided<A>;
39
44
  };
40
45
  /**
41
46
  * Parse command line arguments.
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { parseArgs } from "./parser-Dr4iAGaX.js";
2
2
  import "./utils-N7UlhLbz.js";
3
- import { ArgResolveError, resolveArgs } from "./resolver-Q4k2fgTW.js";
3
+ import { ArgResolveError, resolveArgs } from "./resolver-Bcd8oyPt.js";
4
4
 
5
5
  //#region src/parse.ts
6
6
  const DEFAULT_OPTIONS = {
@@ -8,7 +8,29 @@ const SKIP_POSITIONAL_DEFAULT = -1;
8
8
  * @param args - An arguments that contains {@link ArgSchema | arguments schema}.
9
9
  * @param tokens - An array of {@link ArgToken | tokens}.
10
10
  * @param resolveArgs - An arguments that contains {@link ResolveArgs | resolve arguments}.
11
- * @returns An object that contains the values of the arguments, positional arguments, rest arguments, and {@link AggregateError | validation errors}.
11
+ * @returns An object that contains the values of the arguments, positional arguments, rest arguments, {@link AggregateError | validation errors}, and explicit provision status.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // passed tokens: --port 3000
16
+ *
17
+ * const { values, explicit } = resolveArgs({
18
+ * port: {
19
+ * type: 'number',
20
+ * default: 8080
21
+ * },
22
+ * host: {
23
+ * type: 'string',
24
+ * default: 'localhost'
25
+ * }
26
+ * }, parsedTokens)
27
+ *
28
+ * values.port // 3000
29
+ * values.host // 'localhost'
30
+ *
31
+ * explicit.port // true (explicitly provided)
32
+ * explicit.host // false (not provided, fallback to default)
33
+ * ```
12
34
  */
13
35
  function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT, toKebab = false } = {}) {
14
36
  const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
@@ -108,6 +130,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
108
130
  */
109
131
  const values = Object.create(null);
110
132
  const errors = [];
133
+ const explicit = Object.create(null);
111
134
  function checkTokenName(option, schema, token) {
112
135
  return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
113
136
  }
@@ -118,6 +141,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
118
141
  let positionalsCount = 0;
119
142
  for (const [rawArg, schema] of Object.entries(args)) {
120
143
  const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
144
+ explicit[rawArg] = false;
121
145
  if (schema.required) {
122
146
  const found = optionTokens.find((token) => {
123
147
  return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
@@ -143,6 +167,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
143
167
  errors.push(invalid);
144
168
  continue;
145
169
  }
170
+ explicit[rawArg] = true;
146
171
  if (schema.type === "boolean") token.value = void 0;
147
172
  const [parsedValue, error] = parse(token, arg, schema);
148
173
  if (error) errors.push(error);
@@ -158,7 +183,8 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
158
183
  values,
159
184
  positionals: positionalTokens.map((token) => token.value),
160
185
  rest,
161
- error: errors.length > 0 ? new AggregateError(errors) : void 0
186
+ error: errors.length > 0 ? new AggregateError(errors) : void 0,
187
+ explicit
162
188
  };
163
189
  }
164
190
  function parse(token, option, schema) {
@@ -111,11 +111,40 @@ interface ResolveArgs {
111
111
  toKebab?: boolean;
112
112
  }
113
113
  /**
114
+ * Tracks which arguments were explicitly provided by the user.
115
+ *
116
+ * Each property indicates whether the corresponding argument was explicitly
117
+ * provided (true) or is using a default value or not provided (false).
118
+ */
119
+ type ExplicitlyProvided<A extends Args> = { readonly [K in keyof A]: boolean };
120
+ /**
114
121
  * Resolve command line arguments.
115
122
  * @param args - An arguments that contains {@link ArgSchema | arguments schema}.
116
123
  * @param tokens - An array of {@link ArgToken | tokens}.
117
124
  * @param resolveArgs - An arguments that contains {@link ResolveArgs | resolve arguments}.
118
- * @returns An object that contains the values of the arguments, positional arguments, rest arguments, and {@link AggregateError | validation errors}.
125
+ * @returns An object that contains the values of the arguments, positional arguments, rest arguments, {@link AggregateError | validation errors}, and explicit provision status.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // passed tokens: --port 3000
130
+ *
131
+ * const { values, explicit } = resolveArgs({
132
+ * port: {
133
+ * type: 'number',
134
+ * default: 8080
135
+ * },
136
+ * host: {
137
+ * type: 'string',
138
+ * default: 'localhost'
139
+ * }
140
+ * }, parsedTokens)
141
+ *
142
+ * values.port // 3000
143
+ * values.host // 'localhost'
144
+ *
145
+ * explicit.port // true (explicitly provided)
146
+ * explicit.host // false (not provided, fallback to default)
147
+ * ```
119
148
  */
120
149
  declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
121
150
  shortGrouping,
@@ -126,6 +155,7 @@ declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
126
155
  positionals: string[];
127
156
  rest: string[];
128
157
  error: AggregateError | undefined;
158
+ explicit: ExplicitlyProvided<A>;
129
159
  };
130
160
  /**
131
161
  * An error type for {@link ArgResolveError}.
@@ -142,4 +172,4 @@ declare class ArgResolveError extends Error {
142
172
  constructor(message: string, name: string, type: ArgResolveErrorType, schema: ArgSchema);
143
173
  }
144
174
  //#endregion
145
- export { ArgResolveError as ArgResolveError$1, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs as resolveArgs$1 };
175
+ export { ArgResolveError as ArgResolveError$1, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExplicitlyProvided, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs as resolveArgs$1 };
package/lib/resolver.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./parser-FiQIAw-2.js";
2
- import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-U72Jg6Ll.js";
3
- export { ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs };
2
+ import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExplicitlyProvided, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-C87QZIMT.js";
3
+ export { ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExplicitlyProvided, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs };
package/lib/resolver.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./parser-Dr4iAGaX.js";
2
2
  import "./utils-N7UlhLbz.js";
3
- import { ArgResolveError, resolveArgs } from "./resolver-Q4k2fgTW.js";
3
+ import { ArgResolveError, resolveArgs } from "./resolver-Bcd8oyPt.js";
4
4
 
5
5
  export { ArgResolveError, 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.20.0",
4
+ "version": "0.21.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -52,6 +52,12 @@
52
52
  "require": "./lib/resolver.js",
53
53
  "default": "./lib/resolver.js"
54
54
  },
55
+ "./utils": {
56
+ "types": "./lib/utils.d.ts",
57
+ "import": "./lib/utils.js",
58
+ "require": "./lib/utils.js",
59
+ "default": "./lib/utils.js"
60
+ },
55
61
  "./package.json": "./package.json",
56
62
  "./*": "./*"
57
63
  },
@@ -65,34 +71,34 @@
65
71
  }
66
72
  },
67
73
  "devDependencies": {
68
- "@eslint/markdown": "^6.4.0",
69
- "@kazupon/eslint-config": "^0.29.0",
74
+ "@eslint/markdown": "^6.6.0",
75
+ "@kazupon/eslint-config": "^0.31.1",
70
76
  "@kazupon/prettier-config": "^0.1.1",
71
- "@types/node": "^22.15.27",
72
- "@typescript/native-preview": "7.0.0-dev.20250529.1",
73
- "@vitest/eslint-plugin": "^1.2.1",
74
- "bumpp": "^10.1.1",
75
- "deno": "^2.3.4",
76
- "eslint": "^9.27.0",
77
+ "@types/node": "^22.16.0",
78
+ "@typescript/native-preview": "7.0.0-dev.20250708.1",
79
+ "@vitest/eslint-plugin": "^1.3.4",
80
+ "bumpp": "^10.2.0",
81
+ "deno": "^2.4.1",
82
+ "eslint": "^9.30.1",
77
83
  "eslint-config-prettier": "^10.1.5",
78
84
  "eslint-plugin-jsonc": "^2.20.1",
79
85
  "eslint-plugin-promise": "^7.2.1",
80
- "eslint-plugin-regexp": "^2.7.0",
86
+ "eslint-plugin-regexp": "^2.9.0",
81
87
  "eslint-plugin-unicorn": "^59.0.1",
82
88
  "eslint-plugin-yml": "^1.18.0",
83
89
  "gh-changelogen": "^0.2.8",
84
- "jsr": "^0.13.4",
85
- "jsr-exports-lint": "^0.4.0",
86
- "knip": "^5.59.1",
87
- "lint-staged": "^16.0.0",
90
+ "jsr": "^0.13.5",
91
+ "jsr-exports-lint": "^0.4.1",
92
+ "knip": "^5.61.3",
93
+ "lint-staged": "^16.1.2",
88
94
  "mitata": "^1.0.34",
89
- "pkg-pr-new": "^0.0.51",
90
- "prettier": "^3.5.3",
91
- "tsdown": "^0.12.4",
95
+ "pkg-pr-new": "^0.0.54",
96
+ "prettier": "^3.6.2",
97
+ "tsdown": "^0.12.9",
92
98
  "typescript": "^5.8.3",
93
- "typescript-eslint": "^8.33.0",
94
- "vitest": "^3.1.4",
95
- "zod": "^3.25.41"
99
+ "typescript-eslint": "^8.36.0",
100
+ "vitest": "^3.2.4",
101
+ "zod": "^3.25.76"
96
102
  },
97
103
  "prettier": "@kazupon/prettier-config",
98
104
  "lint-staged": {