@optique/core 1.0.0-dev.741 → 1.0.0-dev.745
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/valueparser.cjs +10 -0
- package/dist/valueparser.d.cts +2 -0
- package/dist/valueparser.d.ts +2 -0
- package/dist/valueparser.js +10 -0
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -91,6 +91,16 @@ function choice(choices, options = {}) {
|
|
|
91
91
|
const stringChoices = choices;
|
|
92
92
|
const stringOptions = options;
|
|
93
93
|
const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
|
|
94
|
+
if (stringOptions.caseInsensitive) {
|
|
95
|
+
const seen = /* @__PURE__ */ new Map();
|
|
96
|
+
for (let i = 0; i < stringChoices.length; i++) {
|
|
97
|
+
const nv = normalizedValues[i];
|
|
98
|
+
const original = stringChoices[i];
|
|
99
|
+
const prev = seen.get(nv);
|
|
100
|
+
if (prev !== void 0 && prev !== original) throw new TypeError(`Ambiguous choices for case-insensitive matching: ${JSON.stringify(prev)} and ${JSON.stringify(original)} both normalize to ${JSON.stringify(nv)}.`);
|
|
101
|
+
seen.set(nv, original);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
94
104
|
return {
|
|
95
105
|
$mode: "sync",
|
|
96
106
|
metavar,
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -206,6 +206,8 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
|
|
|
206
206
|
* @param options Configuration options for the choice parser.
|
|
207
207
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
208
208
|
* specified values.
|
|
209
|
+
* @throws {TypeError} If `caseInsensitive` is `true` and multiple choices
|
|
210
|
+
* normalize to the same lowercase value.
|
|
209
211
|
*/
|
|
210
212
|
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<"sync", T>;
|
|
211
213
|
/**
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -206,6 +206,8 @@ declare function isValueParser<M extends Mode, T>(object: unknown): object is Va
|
|
|
206
206
|
* @param options Configuration options for the choice parser.
|
|
207
207
|
* @returns A {@link ValueParser} that checks if the input matches one of the
|
|
208
208
|
* specified values.
|
|
209
|
+
* @throws {TypeError} If `caseInsensitive` is `true` and multiple choices
|
|
210
|
+
* normalize to the same lowercase value.
|
|
209
211
|
*/
|
|
210
212
|
declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptionsString): ValueParser<"sync", T>;
|
|
211
213
|
/**
|
package/dist/valueparser.js
CHANGED
|
@@ -91,6 +91,16 @@ function choice(choices, options = {}) {
|
|
|
91
91
|
const stringChoices = choices;
|
|
92
92
|
const stringOptions = options;
|
|
93
93
|
const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
|
|
94
|
+
if (stringOptions.caseInsensitive) {
|
|
95
|
+
const seen = /* @__PURE__ */ new Map();
|
|
96
|
+
for (let i = 0; i < stringChoices.length; i++) {
|
|
97
|
+
const nv = normalizedValues[i];
|
|
98
|
+
const original = stringChoices[i];
|
|
99
|
+
const prev = seen.get(nv);
|
|
100
|
+
if (prev !== void 0 && prev !== original) throw new TypeError(`Ambiguous choices for case-insensitive matching: ${JSON.stringify(prev)} and ${JSON.stringify(original)} both normalize to ${JSON.stringify(nv)}.`);
|
|
101
|
+
seen.set(nv, original);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
94
104
|
return {
|
|
95
105
|
$mode: "sync",
|
|
96
106
|
metavar,
|