@optique/core 0.7.0-dev.130 → 0.7.0-dev.133
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/dist/primitives.cjs +1 -1
- package/dist/primitives.js +1 -1
- package/dist/valueparser.cjs +16 -9
- package/dist/valueparser.d.cts +2 -2
- package/dist/valueparser.d.ts +2 -2
- package/dist/valueparser.js +16 -9
- package/package.json +1 -1
package/dist/primitives.cjs
CHANGED
|
@@ -106,7 +106,7 @@ function option(...args) {
|
|
|
106
106
|
if (context.state.success && (valueParser != null || context.state.value)) return {
|
|
107
107
|
success: false,
|
|
108
108
|
consumed: 1,
|
|
109
|
-
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${context.buffer[0]} cannot be used multiple times.`
|
|
109
|
+
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${require_message.optionName(context.buffer[0])} cannot be used multiple times.`
|
|
110
110
|
};
|
|
111
111
|
if (valueParser == null) return {
|
|
112
112
|
success: true,
|
package/dist/primitives.js
CHANGED
|
@@ -106,7 +106,7 @@ function option(...args) {
|
|
|
106
106
|
if (context.state.success && (valueParser != null || context.state.value)) return {
|
|
107
107
|
success: false,
|
|
108
108
|
consumed: 1,
|
|
109
|
-
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${context.buffer[0]} cannot be used multiple times.`
|
|
109
|
+
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${optionName(context.buffer[0])} cannot be used multiple times.`
|
|
110
110
|
};
|
|
111
111
|
if (valueParser == null) return {
|
|
112
112
|
success: true,
|
package/dist/valueparser.cjs
CHANGED
|
@@ -16,25 +16,32 @@ function isValueParser(object) {
|
|
|
16
16
|
* This parser validates that the input string matches one of
|
|
17
17
|
* the specified values. If the input does not match any of the values,
|
|
18
18
|
* it returns an error message indicating the valid options.
|
|
19
|
-
* @param
|
|
19
|
+
* @param choices An array of valid string values that this parser can accept.
|
|
20
20
|
* @param options Configuration options for the choice parser.
|
|
21
21
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
22
22
|
* specified values.
|
|
23
23
|
*/
|
|
24
|
-
function choice(
|
|
25
|
-
const normalizedValues = options.caseInsensitive ?
|
|
24
|
+
function choice(choices, options = {}) {
|
|
25
|
+
const normalizedValues = options.caseInsensitive ? choices.map((v) => v.toLowerCase()) : choices;
|
|
26
26
|
return {
|
|
27
27
|
metavar: options.metavar ?? "TYPE",
|
|
28
28
|
parse(input) {
|
|
29
29
|
const normalizedInput = options.caseInsensitive ? input.toLowerCase() : input;
|
|
30
30
|
const index = normalizedValues.indexOf(normalizedInput);
|
|
31
|
-
if (index < 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (index < 0) {
|
|
32
|
+
let choicesList = [];
|
|
33
|
+
for (let i = 0; i < choices.length; i++) {
|
|
34
|
+
if (i > 0) choicesList = [...choicesList, ...require_message.message`, `];
|
|
35
|
+
choicesList = [...choicesList, ...require_message.message`${choices[i]}`];
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, choices) : options.errors.invalidChoice : require_message.message`Expected one of ${choicesList}, but got ${input}.`
|
|
40
|
+
};
|
|
41
|
+
}
|
|
35
42
|
return {
|
|
36
43
|
success: true,
|
|
37
|
-
value:
|
|
44
|
+
value: choices[index]
|
|
38
45
|
};
|
|
39
46
|
},
|
|
40
47
|
format(value) {
|
|
@@ -42,7 +49,7 @@ function choice(values, options = {}) {
|
|
|
42
49
|
},
|
|
43
50
|
suggest(prefix) {
|
|
44
51
|
const normalizedPrefix = options.caseInsensitive ? prefix.toLowerCase() : prefix;
|
|
45
|
-
return
|
|
52
|
+
return choices.filter((value) => {
|
|
46
53
|
const normalizedValue = options.caseInsensitive ? value.toLowerCase() : value;
|
|
47
54
|
return normalizedValue.startsWith(normalizedPrefix);
|
|
48
55
|
}).map((value) => ({
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -138,12 +138,12 @@ declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
|
|
|
138
138
|
* This parser validates that the input string matches one of
|
|
139
139
|
* the specified values. If the input does not match any of the values,
|
|
140
140
|
* it returns an error message indicating the valid options.
|
|
141
|
-
* @param
|
|
141
|
+
* @param choices An array of valid string values that this parser can accept.
|
|
142
142
|
* @param options Configuration options for the choice parser.
|
|
143
143
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
144
144
|
* specified values.
|
|
145
145
|
*/
|
|
146
|
-
declare function choice<const T extends string>(
|
|
146
|
+
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptions): ValueParser<T>;
|
|
147
147
|
/**
|
|
148
148
|
* Creates a {@link ValueParser} for strings.
|
|
149
149
|
*
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -138,12 +138,12 @@ declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
|
|
|
138
138
|
* This parser validates that the input string matches one of
|
|
139
139
|
* the specified values. If the input does not match any of the values,
|
|
140
140
|
* it returns an error message indicating the valid options.
|
|
141
|
-
* @param
|
|
141
|
+
* @param choices An array of valid string values that this parser can accept.
|
|
142
142
|
* @param options Configuration options for the choice parser.
|
|
143
143
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
144
144
|
* specified values.
|
|
145
145
|
*/
|
|
146
|
-
declare function choice<const T extends string>(
|
|
146
|
+
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptions): ValueParser<T>;
|
|
147
147
|
/**
|
|
148
148
|
* Creates a {@link ValueParser} for strings.
|
|
149
149
|
*
|
package/dist/valueparser.js
CHANGED
|
@@ -16,25 +16,32 @@ function isValueParser(object) {
|
|
|
16
16
|
* This parser validates that the input string matches one of
|
|
17
17
|
* the specified values. If the input does not match any of the values,
|
|
18
18
|
* it returns an error message indicating the valid options.
|
|
19
|
-
* @param
|
|
19
|
+
* @param choices An array of valid string values that this parser can accept.
|
|
20
20
|
* @param options Configuration options for the choice parser.
|
|
21
21
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
22
22
|
* specified values.
|
|
23
23
|
*/
|
|
24
|
-
function choice(
|
|
25
|
-
const normalizedValues = options.caseInsensitive ?
|
|
24
|
+
function choice(choices, options = {}) {
|
|
25
|
+
const normalizedValues = options.caseInsensitive ? choices.map((v) => v.toLowerCase()) : choices;
|
|
26
26
|
return {
|
|
27
27
|
metavar: options.metavar ?? "TYPE",
|
|
28
28
|
parse(input) {
|
|
29
29
|
const normalizedInput = options.caseInsensitive ? input.toLowerCase() : input;
|
|
30
30
|
const index = normalizedValues.indexOf(normalizedInput);
|
|
31
|
-
if (index < 0)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (index < 0) {
|
|
32
|
+
let choicesList = [];
|
|
33
|
+
for (let i = 0; i < choices.length; i++) {
|
|
34
|
+
if (i > 0) choicesList = [...choicesList, ...message`, `];
|
|
35
|
+
choicesList = [...choicesList, ...message`${choices[i]}`];
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, choices) : options.errors.invalidChoice : message`Expected one of ${choicesList}, but got ${input}.`
|
|
40
|
+
};
|
|
41
|
+
}
|
|
35
42
|
return {
|
|
36
43
|
success: true,
|
|
37
|
-
value:
|
|
44
|
+
value: choices[index]
|
|
38
45
|
};
|
|
39
46
|
},
|
|
40
47
|
format(value) {
|
|
@@ -42,7 +49,7 @@ function choice(values, options = {}) {
|
|
|
42
49
|
},
|
|
43
50
|
suggest(prefix) {
|
|
44
51
|
const normalizedPrefix = options.caseInsensitive ? prefix.toLowerCase() : prefix;
|
|
45
|
-
return
|
|
52
|
+
return choices.filter((value) => {
|
|
46
53
|
const normalizedValue = options.caseInsensitive ? value.toLowerCase() : value;
|
|
47
54
|
return normalizedValue.startsWith(normalizedPrefix);
|
|
48
55
|
}).map((value) => ({
|