@optique/core 0.9.0-dev.206 → 0.9.0-dev.211
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/LICENSE +1 -1
- package/dist/constructs.cjs +609 -1339
- package/dist/constructs.d.cts +64 -184
- package/dist/constructs.d.ts +64 -184
- package/dist/constructs.js +609 -1339
- package/dist/facade.cjs +144 -188
- package/dist/facade.d.cts +3 -41
- package/dist/facade.d.ts +3 -41
- package/dist/facade.js +145 -187
- package/dist/index.cjs +0 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/modifiers.cjs +79 -228
- package/dist/modifiers.d.cts +6 -11
- package/dist/modifiers.d.ts +6 -11
- package/dist/modifiers.js +79 -228
- package/dist/parser.cjs +33 -217
- package/dist/parser.d.cts +18 -202
- package/dist/parser.d.ts +18 -202
- package/dist/parser.js +34 -212
- package/dist/primitives.cjs +97 -242
- package/dist/primitives.d.cts +10 -14
- package/dist/primitives.d.ts +10 -14
- package/dist/primitives.js +97 -242
- package/dist/valueparser.cjs +1 -10
- package/dist/valueparser.d.cts +16 -29
- package/dist/valueparser.d.ts +16 -29
- package/dist/valueparser.js +1 -10
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const require_nonempty = require('./nonempty.cjs');
|
|
|
8
8
|
* @return `true` if the object is a {@link ValueParser}, `false` otherwise.
|
|
9
9
|
*/
|
|
10
10
|
function isValueParser(object) {
|
|
11
|
-
return typeof object === "object" && object != null && "
|
|
11
|
+
return typeof object === "object" && object != null && "metavar" in object && typeof object.metavar === "string" && "parse" in object && typeof object.parse === "function" && "format" in object && typeof object.format === "function";
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Implementation of the choice parser for both string and number types.
|
|
@@ -21,7 +21,6 @@ function choice(choices, options = {}) {
|
|
|
21
21
|
const numberChoices = choices;
|
|
22
22
|
const numberOptions = options;
|
|
23
23
|
return {
|
|
24
|
-
$mode: "sync",
|
|
25
24
|
metavar,
|
|
26
25
|
parse(input) {
|
|
27
26
|
const parsed = Number(input);
|
|
@@ -54,7 +53,6 @@ function choice(choices, options = {}) {
|
|
|
54
53
|
const stringOptions = options;
|
|
55
54
|
const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
|
|
56
55
|
return {
|
|
57
|
-
$mode: "sync",
|
|
58
56
|
metavar,
|
|
59
57
|
parse(input) {
|
|
60
58
|
const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
|
|
@@ -126,7 +124,6 @@ function string(options = {}) {
|
|
|
126
124
|
const metavar = options.metavar ?? "STRING";
|
|
127
125
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
128
126
|
return {
|
|
129
|
-
$mode: "sync",
|
|
130
127
|
metavar,
|
|
131
128
|
parse(input) {
|
|
132
129
|
if (options.pattern != null && !options.pattern.test(input)) return {
|
|
@@ -181,7 +178,6 @@ function integer(options) {
|
|
|
181
178
|
const metavar$1 = options.metavar ?? "INTEGER";
|
|
182
179
|
require_nonempty.ensureNonEmptyString(metavar$1);
|
|
183
180
|
return {
|
|
184
|
-
$mode: "sync",
|
|
185
181
|
metavar: metavar$1,
|
|
186
182
|
parse(input) {
|
|
187
183
|
let value;
|
|
@@ -215,7 +211,6 @@ function integer(options) {
|
|
|
215
211
|
const metavar = options?.metavar ?? "INTEGER";
|
|
216
212
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
217
213
|
return {
|
|
218
|
-
$mode: "sync",
|
|
219
214
|
metavar,
|
|
220
215
|
parse(input) {
|
|
221
216
|
if (!input.match(/^-?\d+$/)) return {
|
|
@@ -255,7 +250,6 @@ function float(options = {}) {
|
|
|
255
250
|
const metavar = options.metavar ?? "NUMBER";
|
|
256
251
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
257
252
|
return {
|
|
258
|
-
$mode: "sync",
|
|
259
253
|
metavar,
|
|
260
254
|
parse(input) {
|
|
261
255
|
let value;
|
|
@@ -305,7 +299,6 @@ function url(options = {}) {
|
|
|
305
299
|
const metavar = options.metavar ?? "URL";
|
|
306
300
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
307
301
|
return {
|
|
308
|
-
$mode: "sync",
|
|
309
302
|
metavar,
|
|
310
303
|
parse(input) {
|
|
311
304
|
if (!URL.canParse(input)) return {
|
|
@@ -350,7 +343,6 @@ function locale(options = {}) {
|
|
|
350
343
|
const metavar = options.metavar ?? "LOCALE";
|
|
351
344
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
352
345
|
return {
|
|
353
|
-
$mode: "sync",
|
|
354
346
|
metavar,
|
|
355
347
|
parse(input) {
|
|
356
348
|
let locale$1;
|
|
@@ -620,7 +612,6 @@ function uuid(options = {}) {
|
|
|
620
612
|
const metavar = options.metavar ?? "UUID";
|
|
621
613
|
require_nonempty.ensureNonEmptyString(metavar);
|
|
622
614
|
return {
|
|
623
|
-
$mode: "sync",
|
|
624
615
|
metavar,
|
|
625
616
|
parse(input) {
|
|
626
617
|
if (!uuidRegex.test(input)) return {
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
|
|
2
2
|
import { Message } from "./message.cjs";
|
|
3
|
-
import {
|
|
3
|
+
import { Suggestion } from "./parser.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/valueparser.d.ts
|
|
6
6
|
|
|
@@ -10,20 +10,9 @@ import { Mode, ModeIterable, ModeValue, Suggestion } from "./parser.cjs";
|
|
|
10
10
|
* A `ValueParser` is responsible for converting string input (typically from
|
|
11
11
|
* CLI arguments or option values) into strongly-typed values of type {@link T}.
|
|
12
12
|
*
|
|
13
|
-
* @template M The execution mode of the parser (`"sync"` or `"async"`).
|
|
14
13
|
* @template T The type of value this parser produces.
|
|
15
|
-
* @since 0.9.0 Added the `M` type parameter for sync/async mode support.
|
|
16
14
|
*/
|
|
17
|
-
interface ValueParser<
|
|
18
|
-
/**
|
|
19
|
-
* The execution mode of this value parser.
|
|
20
|
-
*
|
|
21
|
-
* - `"sync"`: The `parse` method returns values directly.
|
|
22
|
-
* - `"async"`: The `parse` method returns Promises.
|
|
23
|
-
*
|
|
24
|
-
* @since 0.9.0
|
|
25
|
-
*/
|
|
26
|
-
readonly $mode: M;
|
|
15
|
+
interface ValueParser<T> {
|
|
27
16
|
/**
|
|
28
17
|
* The metavariable name for this parser. Used in help messages
|
|
29
18
|
* to indicate what kind of value this parser expects. Usually
|
|
@@ -36,10 +25,9 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
36
25
|
* @param input The string input to parse
|
|
37
26
|
* (e.g., the `value` part of `--option=value`).
|
|
38
27
|
* @returns A result object indicating success or failure with an error
|
|
39
|
-
* message.
|
|
40
|
-
* the result.
|
|
28
|
+
* message.
|
|
41
29
|
*/
|
|
42
|
-
parse(input: string):
|
|
30
|
+
parse(input: string): ValueParserResult<T>;
|
|
43
31
|
/**
|
|
44
32
|
* Formats a value of type {@link T} into a string representation.
|
|
45
33
|
* This is useful for displaying the value in help messages or
|
|
@@ -55,10 +43,9 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
55
43
|
*
|
|
56
44
|
* @param prefix The current input prefix to complete.
|
|
57
45
|
* @returns An iterable of suggestion objects.
|
|
58
|
-
* In async mode, returns an AsyncIterable.
|
|
59
46
|
* @since 0.6.0
|
|
60
47
|
*/
|
|
61
|
-
suggest?(prefix: string):
|
|
48
|
+
suggest?(prefix: string): Iterable<Suggestion>;
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
51
|
* Result type returned by {@link ValueParser#parse}.
|
|
@@ -184,7 +171,7 @@ type ChoiceOptions = ChoiceOptionsString;
|
|
|
184
171
|
* @param object The object to check.
|
|
185
172
|
* @return `true` if the object is a {@link ValueParser}, `false` otherwise.
|
|
186
173
|
*/
|
|
187
|
-
declare function isValueParser<
|
|
174
|
+
declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
|
|
188
175
|
/**
|
|
189
176
|
* Creates a {@link ValueParser} that accepts one of multiple
|
|
190
177
|
* string values, so-called enumerated values.
|
|
@@ -197,7 +184,7 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
|
|
|
197
184
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
198
185
|
* specified values.
|
|
199
186
|
*/
|
|
200
|
-
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<
|
|
187
|
+
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<T>;
|
|
201
188
|
/**
|
|
202
189
|
* Creates a {@link ValueParser} that accepts one of multiple
|
|
203
190
|
* number values.
|
|
@@ -211,7 +198,7 @@ declare function choice<const T extends string>(choices: readonly T[], options?:
|
|
|
211
198
|
* specified values.
|
|
212
199
|
* @since 0.9.0
|
|
213
200
|
*/
|
|
214
|
-
declare function choice<const T extends number>(choices: readonly T[], options?: ChoiceOptionsNumber): ValueParser<
|
|
201
|
+
declare function choice<const T extends number>(choices: readonly T[], options?: ChoiceOptionsNumber): ValueParser<T>;
|
|
215
202
|
/**
|
|
216
203
|
* Creates a {@link ValueParser} for strings.
|
|
217
204
|
*
|
|
@@ -226,7 +213,7 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
226
213
|
* @returns A {@link ValueParser} that parses strings according to the
|
|
227
214
|
* specified options.
|
|
228
215
|
*/
|
|
229
|
-
declare function string(options?: StringOptions): ValueParser<
|
|
216
|
+
declare function string(options?: StringOptions): ValueParser<string>;
|
|
230
217
|
/**
|
|
231
218
|
* Options for creating an integer parser that returns a JavaScript `number`.
|
|
232
219
|
*
|
|
@@ -338,14 +325,14 @@ interface IntegerOptionsBigInt {
|
|
|
338
325
|
* @param options Configuration options for the integer parser.
|
|
339
326
|
* @returns A {@link ValueParser} that parses strings into numbers.
|
|
340
327
|
*/
|
|
341
|
-
declare function integer(options?: IntegerOptionsNumber): ValueParser<
|
|
328
|
+
declare function integer(options?: IntegerOptionsNumber): ValueParser<number>;
|
|
342
329
|
/**
|
|
343
330
|
* Creates a ValueParser for integers that returns `bigint` values.
|
|
344
331
|
*
|
|
345
332
|
* @param options Configuration options for the `bigint` parser.
|
|
346
333
|
* @returns A {@link ValueParser} that parses strings into `bigint` values.
|
|
347
334
|
*/
|
|
348
|
-
declare function integer(options: IntegerOptionsBigInt): ValueParser<
|
|
335
|
+
declare function integer(options: IntegerOptionsBigInt): ValueParser<bigint>;
|
|
349
336
|
/**
|
|
350
337
|
* Options for creating a {@link float} parser.
|
|
351
338
|
*/
|
|
@@ -415,7 +402,7 @@ interface FloatOptions {
|
|
|
415
402
|
* @returns A {@link ValueParser} that parses strings into floating-point
|
|
416
403
|
* numbers.
|
|
417
404
|
*/
|
|
418
|
-
declare function float(options?: FloatOptions): ValueParser<
|
|
405
|
+
declare function float(options?: FloatOptions): ValueParser<number>;
|
|
419
406
|
/**
|
|
420
407
|
* Options for creating a {@link url} parser.
|
|
421
408
|
*/
|
|
@@ -462,7 +449,7 @@ interface UrlOptions {
|
|
|
462
449
|
* @param options Configuration options for the URL parser.
|
|
463
450
|
* @returns A {@link ValueParser} that converts string input to `URL` objects.
|
|
464
451
|
*/
|
|
465
|
-
declare function url(options?: UrlOptions): ValueParser<
|
|
452
|
+
declare function url(options?: UrlOptions): ValueParser<URL>;
|
|
466
453
|
/**
|
|
467
454
|
* Options for creating a {@link locale} parser.
|
|
468
455
|
*/
|
|
@@ -497,7 +484,7 @@ interface LocaleOptions {
|
|
|
497
484
|
* @returns A {@link ValueParser} that converts string input to `Intl.Locale`
|
|
498
485
|
* objects.
|
|
499
486
|
*/
|
|
500
|
-
declare function locale(options?: LocaleOptions): ValueParser<
|
|
487
|
+
declare function locale(options?: LocaleOptions): ValueParser<Intl.Locale>;
|
|
501
488
|
/**
|
|
502
489
|
* Type representing a UUID string.
|
|
503
490
|
*
|
|
@@ -554,6 +541,6 @@ interface UuidOptions {
|
|
|
554
541
|
* @returns A {@link ValueParser} that converts string input to {@link Uuid}
|
|
555
542
|
* strings.
|
|
556
543
|
*/
|
|
557
|
-
declare function uuid(options?: UuidOptions): ValueParser<
|
|
544
|
+
declare function uuid(options?: UuidOptions): ValueParser<Uuid>;
|
|
558
545
|
//#endregion
|
|
559
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, type
|
|
546
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, type NonEmptyString, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, ensureNonEmptyString, float, integer, isNonEmptyString, isValueParser, locale, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
2
2
|
import { Message } from "./message.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Suggestion } from "./parser.js";
|
|
4
4
|
|
|
5
5
|
//#region src/valueparser.d.ts
|
|
6
6
|
|
|
@@ -10,20 +10,9 @@ import { Mode, ModeIterable, ModeValue, Suggestion } from "./parser.js";
|
|
|
10
10
|
* A `ValueParser` is responsible for converting string input (typically from
|
|
11
11
|
* CLI arguments or option values) into strongly-typed values of type {@link T}.
|
|
12
12
|
*
|
|
13
|
-
* @template M The execution mode of the parser (`"sync"` or `"async"`).
|
|
14
13
|
* @template T The type of value this parser produces.
|
|
15
|
-
* @since 0.9.0 Added the `M` type parameter for sync/async mode support.
|
|
16
14
|
*/
|
|
17
|
-
interface ValueParser<
|
|
18
|
-
/**
|
|
19
|
-
* The execution mode of this value parser.
|
|
20
|
-
*
|
|
21
|
-
* - `"sync"`: The `parse` method returns values directly.
|
|
22
|
-
* - `"async"`: The `parse` method returns Promises.
|
|
23
|
-
*
|
|
24
|
-
* @since 0.9.0
|
|
25
|
-
*/
|
|
26
|
-
readonly $mode: M;
|
|
15
|
+
interface ValueParser<T> {
|
|
27
16
|
/**
|
|
28
17
|
* The metavariable name for this parser. Used in help messages
|
|
29
18
|
* to indicate what kind of value this parser expects. Usually
|
|
@@ -36,10 +25,9 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
36
25
|
* @param input The string input to parse
|
|
37
26
|
* (e.g., the `value` part of `--option=value`).
|
|
38
27
|
* @returns A result object indicating success or failure with an error
|
|
39
|
-
* message.
|
|
40
|
-
* the result.
|
|
28
|
+
* message.
|
|
41
29
|
*/
|
|
42
|
-
parse(input: string):
|
|
30
|
+
parse(input: string): ValueParserResult<T>;
|
|
43
31
|
/**
|
|
44
32
|
* Formats a value of type {@link T} into a string representation.
|
|
45
33
|
* This is useful for displaying the value in help messages or
|
|
@@ -55,10 +43,9 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
|
|
|
55
43
|
*
|
|
56
44
|
* @param prefix The current input prefix to complete.
|
|
57
45
|
* @returns An iterable of suggestion objects.
|
|
58
|
-
* In async mode, returns an AsyncIterable.
|
|
59
46
|
* @since 0.6.0
|
|
60
47
|
*/
|
|
61
|
-
suggest?(prefix: string):
|
|
48
|
+
suggest?(prefix: string): Iterable<Suggestion>;
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
51
|
* Result type returned by {@link ValueParser#parse}.
|
|
@@ -184,7 +171,7 @@ type ChoiceOptions = ChoiceOptionsString;
|
|
|
184
171
|
* @param object The object to check.
|
|
185
172
|
* @return `true` if the object is a {@link ValueParser}, `false` otherwise.
|
|
186
173
|
*/
|
|
187
|
-
declare function isValueParser<
|
|
174
|
+
declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
|
|
188
175
|
/**
|
|
189
176
|
* Creates a {@link ValueParser} that accepts one of multiple
|
|
190
177
|
* string values, so-called enumerated values.
|
|
@@ -197,7 +184,7 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
|
|
|
197
184
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
198
185
|
* specified values.
|
|
199
186
|
*/
|
|
200
|
-
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<
|
|
187
|
+
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<T>;
|
|
201
188
|
/**
|
|
202
189
|
* Creates a {@link ValueParser} that accepts one of multiple
|
|
203
190
|
* number values.
|
|
@@ -211,7 +198,7 @@ declare function choice<const T extends string>(choices: readonly T[], options?:
|
|
|
211
198
|
* specified values.
|
|
212
199
|
* @since 0.9.0
|
|
213
200
|
*/
|
|
214
|
-
declare function choice<const T extends number>(choices: readonly T[], options?: ChoiceOptionsNumber): ValueParser<
|
|
201
|
+
declare function choice<const T extends number>(choices: readonly T[], options?: ChoiceOptionsNumber): ValueParser<T>;
|
|
215
202
|
/**
|
|
216
203
|
* Creates a {@link ValueParser} for strings.
|
|
217
204
|
*
|
|
@@ -226,7 +213,7 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
226
213
|
* @returns A {@link ValueParser} that parses strings according to the
|
|
227
214
|
* specified options.
|
|
228
215
|
*/
|
|
229
|
-
declare function string(options?: StringOptions): ValueParser<
|
|
216
|
+
declare function string(options?: StringOptions): ValueParser<string>;
|
|
230
217
|
/**
|
|
231
218
|
* Options for creating an integer parser that returns a JavaScript `number`.
|
|
232
219
|
*
|
|
@@ -338,14 +325,14 @@ interface IntegerOptionsBigInt {
|
|
|
338
325
|
* @param options Configuration options for the integer parser.
|
|
339
326
|
* @returns A {@link ValueParser} that parses strings into numbers.
|
|
340
327
|
*/
|
|
341
|
-
declare function integer(options?: IntegerOptionsNumber): ValueParser<
|
|
328
|
+
declare function integer(options?: IntegerOptionsNumber): ValueParser<number>;
|
|
342
329
|
/**
|
|
343
330
|
* Creates a ValueParser for integers that returns `bigint` values.
|
|
344
331
|
*
|
|
345
332
|
* @param options Configuration options for the `bigint` parser.
|
|
346
333
|
* @returns A {@link ValueParser} that parses strings into `bigint` values.
|
|
347
334
|
*/
|
|
348
|
-
declare function integer(options: IntegerOptionsBigInt): ValueParser<
|
|
335
|
+
declare function integer(options: IntegerOptionsBigInt): ValueParser<bigint>;
|
|
349
336
|
/**
|
|
350
337
|
* Options for creating a {@link float} parser.
|
|
351
338
|
*/
|
|
@@ -415,7 +402,7 @@ interface FloatOptions {
|
|
|
415
402
|
* @returns A {@link ValueParser} that parses strings into floating-point
|
|
416
403
|
* numbers.
|
|
417
404
|
*/
|
|
418
|
-
declare function float(options?: FloatOptions): ValueParser<
|
|
405
|
+
declare function float(options?: FloatOptions): ValueParser<number>;
|
|
419
406
|
/**
|
|
420
407
|
* Options for creating a {@link url} parser.
|
|
421
408
|
*/
|
|
@@ -462,7 +449,7 @@ interface UrlOptions {
|
|
|
462
449
|
* @param options Configuration options for the URL parser.
|
|
463
450
|
* @returns A {@link ValueParser} that converts string input to `URL` objects.
|
|
464
451
|
*/
|
|
465
|
-
declare function url(options?: UrlOptions): ValueParser<
|
|
452
|
+
declare function url(options?: UrlOptions): ValueParser<URL>;
|
|
466
453
|
/**
|
|
467
454
|
* Options for creating a {@link locale} parser.
|
|
468
455
|
*/
|
|
@@ -497,7 +484,7 @@ interface LocaleOptions {
|
|
|
497
484
|
* @returns A {@link ValueParser} that converts string input to `Intl.Locale`
|
|
498
485
|
* objects.
|
|
499
486
|
*/
|
|
500
|
-
declare function locale(options?: LocaleOptions): ValueParser<
|
|
487
|
+
declare function locale(options?: LocaleOptions): ValueParser<Intl.Locale>;
|
|
501
488
|
/**
|
|
502
489
|
* Type representing a UUID string.
|
|
503
490
|
*
|
|
@@ -554,6 +541,6 @@ interface UuidOptions {
|
|
|
554
541
|
* @returns A {@link ValueParser} that converts string input to {@link Uuid}
|
|
555
542
|
* strings.
|
|
556
543
|
*/
|
|
557
|
-
declare function uuid(options?: UuidOptions): ValueParser<
|
|
544
|
+
declare function uuid(options?: UuidOptions): ValueParser<Uuid>;
|
|
558
545
|
//#endregion
|
|
559
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, type
|
|
546
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, type NonEmptyString, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, ensureNonEmptyString, float, integer, isNonEmptyString, isValueParser, locale, string, url, uuid };
|
package/dist/valueparser.js
CHANGED
|
@@ -8,7 +8,7 @@ import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
|
8
8
|
* @return `true` if the object is a {@link ValueParser}, `false` otherwise.
|
|
9
9
|
*/
|
|
10
10
|
function isValueParser(object) {
|
|
11
|
-
return typeof object === "object" && object != null && "
|
|
11
|
+
return typeof object === "object" && object != null && "metavar" in object && typeof object.metavar === "string" && "parse" in object && typeof object.parse === "function" && "format" in object && typeof object.format === "function";
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Implementation of the choice parser for both string and number types.
|
|
@@ -21,7 +21,6 @@ function choice(choices, options = {}) {
|
|
|
21
21
|
const numberChoices = choices;
|
|
22
22
|
const numberOptions = options;
|
|
23
23
|
return {
|
|
24
|
-
$mode: "sync",
|
|
25
24
|
metavar,
|
|
26
25
|
parse(input) {
|
|
27
26
|
const parsed = Number(input);
|
|
@@ -54,7 +53,6 @@ function choice(choices, options = {}) {
|
|
|
54
53
|
const stringOptions = options;
|
|
55
54
|
const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
|
|
56
55
|
return {
|
|
57
|
-
$mode: "sync",
|
|
58
56
|
metavar,
|
|
59
57
|
parse(input) {
|
|
60
58
|
const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
|
|
@@ -126,7 +124,6 @@ function string(options = {}) {
|
|
|
126
124
|
const metavar = options.metavar ?? "STRING";
|
|
127
125
|
ensureNonEmptyString(metavar);
|
|
128
126
|
return {
|
|
129
|
-
$mode: "sync",
|
|
130
127
|
metavar,
|
|
131
128
|
parse(input) {
|
|
132
129
|
if (options.pattern != null && !options.pattern.test(input)) return {
|
|
@@ -181,7 +178,6 @@ function integer(options) {
|
|
|
181
178
|
const metavar$1 = options.metavar ?? "INTEGER";
|
|
182
179
|
ensureNonEmptyString(metavar$1);
|
|
183
180
|
return {
|
|
184
|
-
$mode: "sync",
|
|
185
181
|
metavar: metavar$1,
|
|
186
182
|
parse(input) {
|
|
187
183
|
let value;
|
|
@@ -215,7 +211,6 @@ function integer(options) {
|
|
|
215
211
|
const metavar = options?.metavar ?? "INTEGER";
|
|
216
212
|
ensureNonEmptyString(metavar);
|
|
217
213
|
return {
|
|
218
|
-
$mode: "sync",
|
|
219
214
|
metavar,
|
|
220
215
|
parse(input) {
|
|
221
216
|
if (!input.match(/^-?\d+$/)) return {
|
|
@@ -255,7 +250,6 @@ function float(options = {}) {
|
|
|
255
250
|
const metavar = options.metavar ?? "NUMBER";
|
|
256
251
|
ensureNonEmptyString(metavar);
|
|
257
252
|
return {
|
|
258
|
-
$mode: "sync",
|
|
259
253
|
metavar,
|
|
260
254
|
parse(input) {
|
|
261
255
|
let value;
|
|
@@ -305,7 +299,6 @@ function url(options = {}) {
|
|
|
305
299
|
const metavar = options.metavar ?? "URL";
|
|
306
300
|
ensureNonEmptyString(metavar);
|
|
307
301
|
return {
|
|
308
|
-
$mode: "sync",
|
|
309
302
|
metavar,
|
|
310
303
|
parse(input) {
|
|
311
304
|
if (!URL.canParse(input)) return {
|
|
@@ -350,7 +343,6 @@ function locale(options = {}) {
|
|
|
350
343
|
const metavar = options.metavar ?? "LOCALE";
|
|
351
344
|
ensureNonEmptyString(metavar);
|
|
352
345
|
return {
|
|
353
|
-
$mode: "sync",
|
|
354
346
|
metavar,
|
|
355
347
|
parse(input) {
|
|
356
348
|
let locale$1;
|
|
@@ -620,7 +612,6 @@ function uuid(options = {}) {
|
|
|
620
612
|
const metavar = options.metavar ?? "UUID";
|
|
621
613
|
ensureNonEmptyString(metavar);
|
|
622
614
|
return {
|
|
623
|
-
$mode: "sync",
|
|
624
615
|
metavar,
|
|
625
616
|
parse(input) {
|
|
626
617
|
if (!uuidRegex.test(input)) return {
|