Added conversion

This commit is contained in:
Sebastian Seedorf
2020-05-28 00:52:52 +02:00
parent 741b96ee50
commit 1ddb84234e
5 changed files with 161 additions and 21 deletions

View File

@@ -5,6 +5,13 @@ export function isNumber(
): Validator {
return {
type: "isNumber",
convert: (value: any) => {
if (typeof value === "string" || value instanceof String) {
const num = Number(value);
return Number.isNaN(num) ? value : num;
}
return value;
},
check: (value: any) => {
if (value === null || value === undefined) return;
if (allowNaN && Number.isNaN(value)) return;