@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.
@@ -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,
@@ -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
  /**
@@ -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
  /**
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.741+f6595c2a",
3
+ "version": "1.0.0-dev.745+a12a4fbd",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",