args-tokens 0.13.3 → 0.14.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/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/parser.d.ts +4 -0
- package/lib/{resolver-Di82Qgwx.js → resolver-BFy1oVrL.js} +5 -3
- package/lib/resolver.d.ts +7 -2
- package/lib/resolver.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParserOptions } from './parser.js';
|
|
2
2
|
export { ArgToken, parseArgs } from './parser.js';
|
|
3
3
|
import { ArgOptions, ArgValues } from './resolver.js';
|
|
4
|
-
export { ArgOptionSchema, OptionResolveError, resolveArgs } from './resolver.js';
|
|
4
|
+
export { ArgOptionSchema, OptionResolveError, OptionResolveErrorType, resolveArgs } from './resolver.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Parse options for {@link parse} function.
|
package/lib/index.js
CHANGED
package/lib/parser.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Entry point of argument parser.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
2
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
|
|
@@ -137,14 +137,16 @@ function resolveArgs(options, tokens) {
|
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
function createRequireError(option, schema) {
|
|
140
|
-
return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, schema);
|
|
140
|
+
return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
|
|
141
141
|
}
|
|
142
142
|
var OptionResolveError = class extends Error {
|
|
143
143
|
name;
|
|
144
144
|
schema;
|
|
145
|
-
|
|
145
|
+
type;
|
|
146
|
+
constructor(message, name, type, schema) {
|
|
146
147
|
super(message);
|
|
147
148
|
this.name = name;
|
|
149
|
+
this.type = type;
|
|
148
150
|
this.schema = schema;
|
|
149
151
|
}
|
|
150
152
|
};
|
|
@@ -167,7 +169,7 @@ function isNumeric(str) {
|
|
|
167
169
|
return str.trim() !== "" && !isNaN(str);
|
|
168
170
|
}
|
|
169
171
|
function createTypeError(option, schema) {
|
|
170
|
-
return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, schema);
|
|
172
|
+
return new OptionResolveError(`Option '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, "type", schema);
|
|
171
173
|
}
|
|
172
174
|
function resolveOptionValue(token, schema) {
|
|
173
175
|
if (token.value) return schema.type === "number" ? +token.value : token.value;
|
package/lib/resolver.d.ts
CHANGED
|
@@ -64,14 +64,19 @@ declare function resolveArgs<T extends ArgOptions>(options: T, tokens: ArgToken[
|
|
|
64
64
|
error: AggregateError | undefined
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
|
+
* An error type for {@link OptionResolveError}.
|
|
68
|
+
*/
|
|
69
|
+
type OptionResolveErrorType = "type" | "required";
|
|
70
|
+
/**
|
|
67
71
|
* An error that occurs when resolving options.
|
|
68
72
|
* This error is thrown when the option is not valid.
|
|
69
73
|
*/
|
|
70
74
|
declare class OptionResolveError extends Error {
|
|
71
75
|
name: string;
|
|
72
76
|
schema: ArgOptionSchema;
|
|
73
|
-
|
|
77
|
+
type: OptionResolveErrorType;
|
|
78
|
+
constructor(message: string, name: string, type: OptionResolveErrorType, schema: ArgOptionSchema);
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
export { OptionResolveError, resolveArgs };
|
|
77
|
-
export type { ArgOptionSchema, ArgOptions, ArgValues };
|
|
82
|
+
export type { ArgOptionSchema, ArgOptions, ArgValues, OptionResolveErrorType };
|
package/lib/resolver.js
CHANGED