@optique/core 1.0.0-dev.717 → 1.0.0-dev.725
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 +7 -8
- package/dist/valueparser.js +7 -8
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -368,6 +368,10 @@ function float(options = {}) {
|
|
|
368
368
|
$mode: "sync",
|
|
369
369
|
metavar,
|
|
370
370
|
parse(input) {
|
|
371
|
+
const invalidNumber = (i) => ({
|
|
372
|
+
success: false,
|
|
373
|
+
error: options.errors?.invalidNumber ? typeof options.errors.invalidNumber === "function" ? options.errors.invalidNumber(i) : options.errors.invalidNumber : require_message.message`Expected a valid number, but got ${i}.`
|
|
374
|
+
});
|
|
371
375
|
let value;
|
|
372
376
|
const lowerInput = input.toLowerCase();
|
|
373
377
|
if (lowerInput === "nan" && options.allowNaN) value = NaN;
|
|
@@ -375,14 +379,9 @@ function float(options = {}) {
|
|
|
375
379
|
else if (lowerInput === "-infinity" && options.allowInfinity) value = -Infinity;
|
|
376
380
|
else if (floatRegex.test(input)) {
|
|
377
381
|
value = Number(input);
|
|
378
|
-
if (Number.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
};
|
|
382
|
-
} else return {
|
|
383
|
-
success: false,
|
|
384
|
-
error: options.errors?.invalidNumber ? typeof options.errors.invalidNumber === "function" ? options.errors.invalidNumber(input) : options.errors.invalidNumber : require_message.message`Expected a valid number, but got ${input}.`
|
|
385
|
-
};
|
|
382
|
+
if (!Number.isFinite(value) && !options.allowInfinity) return invalidNumber(input);
|
|
383
|
+
if (Number.isNaN(value)) return invalidNumber(input);
|
|
384
|
+
} else return invalidNumber(input);
|
|
386
385
|
if (options.min != null && value < options.min) return {
|
|
387
386
|
success: false,
|
|
388
387
|
error: options.errors?.belowMinimum ? typeof options.errors.belowMinimum === "function" ? options.errors.belowMinimum(value, options.min) : options.errors.belowMinimum : require_message.message`Expected a value greater than or equal to ${require_message.text(options.min.toLocaleString("en"))}, but got ${input}.`
|
package/dist/valueparser.js
CHANGED
|
@@ -368,6 +368,10 @@ function float(options = {}) {
|
|
|
368
368
|
$mode: "sync",
|
|
369
369
|
metavar,
|
|
370
370
|
parse(input) {
|
|
371
|
+
const invalidNumber = (i) => ({
|
|
372
|
+
success: false,
|
|
373
|
+
error: options.errors?.invalidNumber ? typeof options.errors.invalidNumber === "function" ? options.errors.invalidNumber(i) : options.errors.invalidNumber : message`Expected a valid number, but got ${i}.`
|
|
374
|
+
});
|
|
371
375
|
let value;
|
|
372
376
|
const lowerInput = input.toLowerCase();
|
|
373
377
|
if (lowerInput === "nan" && options.allowNaN) value = NaN;
|
|
@@ -375,14 +379,9 @@ function float(options = {}) {
|
|
|
375
379
|
else if (lowerInput === "-infinity" && options.allowInfinity) value = -Infinity;
|
|
376
380
|
else if (floatRegex.test(input)) {
|
|
377
381
|
value = Number(input);
|
|
378
|
-
if (Number.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
};
|
|
382
|
-
} else return {
|
|
383
|
-
success: false,
|
|
384
|
-
error: options.errors?.invalidNumber ? typeof options.errors.invalidNumber === "function" ? options.errors.invalidNumber(input) : options.errors.invalidNumber : message`Expected a valid number, but got ${input}.`
|
|
385
|
-
};
|
|
382
|
+
if (!Number.isFinite(value) && !options.allowInfinity) return invalidNumber(input);
|
|
383
|
+
if (Number.isNaN(value)) return invalidNumber(input);
|
|
384
|
+
} else return invalidNumber(input);
|
|
386
385
|
if (options.min != null && value < options.min) return {
|
|
387
386
|
success: false,
|
|
388
387
|
error: options.errors?.belowMinimum ? typeof options.errors.belowMinimum === "function" ? options.errors.belowMinimum(value, options.min) : options.errors.belowMinimum : message`Expected a value greater than or equal to ${text(options.min.toLocaleString("en"))}, but got ${input}.`
|