@optique/core 1.0.0-dev.751 → 1.0.0-dev.764

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.
@@ -19,7 +19,26 @@ function choice(choices, options = {}) {
19
19
  require_nonempty.ensureNonEmptyString(metavar);
20
20
  const isNumberChoice = choices.length > 0 && typeof choices[0] === "number";
21
21
  if (isNumberChoice) {
22
- const numberChoices = choices;
22
+ const numberChoices = (() => {
23
+ const seen = /* @__PURE__ */ new Set();
24
+ let hasPositiveZero = false;
25
+ let hasNegativeZero = false;
26
+ const result = [];
27
+ for (const v of choices) {
28
+ if (Object.is(v, -0)) {
29
+ if (hasNegativeZero) continue;
30
+ hasNegativeZero = true;
31
+ } else if (Object.is(v, 0)) {
32
+ if (hasPositiveZero) continue;
33
+ hasPositiveZero = true;
34
+ } else {
35
+ if (seen.has(v)) continue;
36
+ seen.add(v);
37
+ }
38
+ result.push(v);
39
+ }
40
+ return result;
41
+ })();
23
42
  const numberOptions = options;
24
43
  const hasNaN = numberChoices.some((v) => Number.isNaN(v));
25
44
  const validNumberChoices = hasNaN ? numberChoices.filter((v) => !Number.isNaN(v)) : numberChoices;
@@ -89,7 +108,7 @@ function choice(choices, options = {}) {
89
108
  }
90
109
  };
91
110
  }
92
- const stringChoices = choices;
111
+ const stringChoices = [...new Set(choices)];
93
112
  const stringOptions = options;
94
113
  const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
95
114
  if (stringOptions.caseInsensitive) {
@@ -105,7 +124,7 @@ function choice(choices, options = {}) {
105
124
  return {
106
125
  $mode: "sync",
107
126
  metavar,
108
- choices,
127
+ choices: stringChoices,
109
128
  parse(input) {
110
129
  const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
111
130
  const index = normalizedValues.indexOf(normalizedInput);
@@ -19,7 +19,26 @@ function choice(choices, options = {}) {
19
19
  ensureNonEmptyString(metavar);
20
20
  const isNumberChoice = choices.length > 0 && typeof choices[0] === "number";
21
21
  if (isNumberChoice) {
22
- const numberChoices = choices;
22
+ const numberChoices = (() => {
23
+ const seen = /* @__PURE__ */ new Set();
24
+ let hasPositiveZero = false;
25
+ let hasNegativeZero = false;
26
+ const result = [];
27
+ for (const v of choices) {
28
+ if (Object.is(v, -0)) {
29
+ if (hasNegativeZero) continue;
30
+ hasNegativeZero = true;
31
+ } else if (Object.is(v, 0)) {
32
+ if (hasPositiveZero) continue;
33
+ hasPositiveZero = true;
34
+ } else {
35
+ if (seen.has(v)) continue;
36
+ seen.add(v);
37
+ }
38
+ result.push(v);
39
+ }
40
+ return result;
41
+ })();
23
42
  const numberOptions = options;
24
43
  const hasNaN = numberChoices.some((v) => Number.isNaN(v));
25
44
  const validNumberChoices = hasNaN ? numberChoices.filter((v) => !Number.isNaN(v)) : numberChoices;
@@ -89,7 +108,7 @@ function choice(choices, options = {}) {
89
108
  }
90
109
  };
91
110
  }
92
- const stringChoices = choices;
111
+ const stringChoices = [...new Set(choices)];
93
112
  const stringOptions = options;
94
113
  const normalizedValues = stringOptions.caseInsensitive ? stringChoices.map((v) => v.toLowerCase()) : stringChoices;
95
114
  if (stringOptions.caseInsensitive) {
@@ -105,7 +124,7 @@ function choice(choices, options = {}) {
105
124
  return {
106
125
  $mode: "sync",
107
126
  metavar,
108
- choices,
127
+ choices: stringChoices,
109
128
  parse(input) {
110
129
  const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
111
130
  const index = normalizedValues.indexOf(normalizedInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.751+3ec7e203",
3
+ "version": "1.0.0-dev.764+b6aec70a",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",