@optique/core 1.2.0-dev.2242 → 1.2.0-dev.2244
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/suggestion.cjs +3 -2
- package/dist/suggestion.js +3 -2
- package/dist/valueparser.cjs +12 -3
- package/dist/valueparser.js +12 -3
- package/package.json +2 -2
package/dist/suggestion.cjs
CHANGED
|
@@ -283,12 +283,13 @@ function appendValueHint(base, input, candidates, options) {
|
|
|
283
283
|
...options
|
|
284
284
|
} : void 0);
|
|
285
285
|
const suggestionMsg = createSuggestionMessage(suggestions);
|
|
286
|
-
|
|
286
|
+
if (suggestionMsg.length === 0) return base;
|
|
287
|
+
return base.length > 0 ? [
|
|
287
288
|
...base,
|
|
288
289
|
require_message.lineBreak(),
|
|
289
290
|
require_message.lineBreak(),
|
|
290
291
|
...suggestionMsg
|
|
291
|
-
] :
|
|
292
|
+
] : suggestionMsg;
|
|
292
293
|
}
|
|
293
294
|
/**
|
|
294
295
|
* Creates a unique key for a suggestion to enable deduplication.
|
package/dist/suggestion.js
CHANGED
|
@@ -283,12 +283,13 @@ function appendValueHint(base, input, candidates, options) {
|
|
|
283
283
|
...options
|
|
284
284
|
} : void 0);
|
|
285
285
|
const suggestionMsg = createSuggestionMessage(suggestions);
|
|
286
|
-
|
|
286
|
+
if (suggestionMsg.length === 0) return base;
|
|
287
|
+
return base.length > 0 ? [
|
|
287
288
|
...base,
|
|
288
289
|
lineBreak(),
|
|
289
290
|
lineBreak(),
|
|
290
291
|
...suggestionMsg
|
|
291
|
-
] :
|
|
292
|
+
] : suggestionMsg;
|
|
292
293
|
}
|
|
293
294
|
/**
|
|
294
295
|
* Creates a unique key for a suggestion to enable deduplication.
|
package/dist/valueparser.cjs
CHANGED
|
@@ -142,9 +142,18 @@ function choice(choices, options = {}) {
|
|
|
142
142
|
const stringSuggest = stringOptions.suggest;
|
|
143
143
|
if (stringSuggest !== void 0) {
|
|
144
144
|
const isValidString = stringSuggest === "nearest" || stringSuggest === "never";
|
|
145
|
-
const
|
|
145
|
+
const isArray = Array.isArray(stringSuggest);
|
|
146
|
+
const isValidObject = typeof stringSuggest === "object" && stringSuggest !== null && !isArray;
|
|
146
147
|
const isValidFunction = typeof stringSuggest === "function";
|
|
147
|
-
if (!isValidString && !isValidObject && !isValidFunction)
|
|
148
|
+
if (!isValidString && !isValidObject && !isValidFunction) {
|
|
149
|
+
const actualType = isArray ? "array" : stringSuggest === null ? "null" : typeof stringSuggest;
|
|
150
|
+
throw new TypeError(`Expected suggest to be "nearest", "never", an object, or a function, but got ${actualType}: ${String(stringSuggest)}.`);
|
|
151
|
+
}
|
|
152
|
+
if (isValidObject) {
|
|
153
|
+
const obj = stringSuggest;
|
|
154
|
+
if (obj.maxDistance !== void 0 && (typeof obj.maxDistance !== "number" || !isFinite(obj.maxDistance))) throw new TypeError(`Expected suggest.maxDistance to be a finite number, but got ${typeof obj.maxDistance}: ${String(obj.maxDistance)}.`);
|
|
155
|
+
if (obj.maxSuggestions !== void 0 && (typeof obj.maxSuggestions !== "number" || !isFinite(obj.maxSuggestions))) throw new TypeError(`Expected suggest.maxSuggestions to be a finite number, but got ${typeof obj.maxSuggestions}: ${String(obj.maxSuggestions)}.`);
|
|
156
|
+
}
|
|
148
157
|
}
|
|
149
158
|
return {
|
|
150
159
|
mode: "sync",
|
|
@@ -269,7 +278,7 @@ function formatStringChoiceError(input, choices, invalidChoice, suggest) {
|
|
|
269
278
|
if (suggest === "nearest") return require_suggestion.appendValueHint(base, input, choices);
|
|
270
279
|
if (typeof suggest === "function") {
|
|
271
280
|
const hints = suggest(input, choices);
|
|
272
|
-
if (!hints || hints.length === 0) return base;
|
|
281
|
+
if (!Array.isArray(hints) || hints.length === 0) return base;
|
|
273
282
|
const suggestionMsg = require_suggestion.createSuggestionMessage(hints);
|
|
274
283
|
return suggestionMsg.length > 0 ? [
|
|
275
284
|
...base,
|
package/dist/valueparser.js
CHANGED
|
@@ -142,9 +142,18 @@ function choice(choices, options = {}) {
|
|
|
142
142
|
const stringSuggest = stringOptions.suggest;
|
|
143
143
|
if (stringSuggest !== void 0) {
|
|
144
144
|
const isValidString = stringSuggest === "nearest" || stringSuggest === "never";
|
|
145
|
-
const
|
|
145
|
+
const isArray = Array.isArray(stringSuggest);
|
|
146
|
+
const isValidObject = typeof stringSuggest === "object" && stringSuggest !== null && !isArray;
|
|
146
147
|
const isValidFunction = typeof stringSuggest === "function";
|
|
147
|
-
if (!isValidString && !isValidObject && !isValidFunction)
|
|
148
|
+
if (!isValidString && !isValidObject && !isValidFunction) {
|
|
149
|
+
const actualType = isArray ? "array" : stringSuggest === null ? "null" : typeof stringSuggest;
|
|
150
|
+
throw new TypeError(`Expected suggest to be "nearest", "never", an object, or a function, but got ${actualType}: ${String(stringSuggest)}.`);
|
|
151
|
+
}
|
|
152
|
+
if (isValidObject) {
|
|
153
|
+
const obj = stringSuggest;
|
|
154
|
+
if (obj.maxDistance !== void 0 && (typeof obj.maxDistance !== "number" || !isFinite(obj.maxDistance))) throw new TypeError(`Expected suggest.maxDistance to be a finite number, but got ${typeof obj.maxDistance}: ${String(obj.maxDistance)}.`);
|
|
155
|
+
if (obj.maxSuggestions !== void 0 && (typeof obj.maxSuggestions !== "number" || !isFinite(obj.maxSuggestions))) throw new TypeError(`Expected suggest.maxSuggestions to be a finite number, but got ${typeof obj.maxSuggestions}: ${String(obj.maxSuggestions)}.`);
|
|
156
|
+
}
|
|
148
157
|
}
|
|
149
158
|
return {
|
|
150
159
|
mode: "sync",
|
|
@@ -269,7 +278,7 @@ function formatStringChoiceError(input, choices, invalidChoice, suggest) {
|
|
|
269
278
|
if (suggest === "nearest") return appendValueHint(base, input, choices);
|
|
270
279
|
if (typeof suggest === "function") {
|
|
271
280
|
const hints = suggest(input, choices);
|
|
272
|
-
if (!hints || hints.length === 0) return base;
|
|
281
|
+
if (!Array.isArray(hints) || hints.length === 0) return base;
|
|
273
282
|
const suggestionMsg = createSuggestionMessage(hints);
|
|
274
283
|
return suggestionMsg.length > 0 ? [
|
|
275
284
|
...base,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.2.0-dev.
|
|
3
|
+
"version": "1.2.0-dev.2244",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -216,7 +216,7 @@
|
|
|
216
216
|
"fast-check": "^4.7.0",
|
|
217
217
|
"tsdown": "^0.13.0",
|
|
218
218
|
"typescript": "^5.8.3",
|
|
219
|
-
"@optique/env": "1.2.0-dev.
|
|
219
|
+
"@optique/env": "1.2.0-dev.2244+b3c70b3c"
|
|
220
220
|
},
|
|
221
221
|
"scripts": {
|
|
222
222
|
"build": "tsdown",
|