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

@@ -126,6 +126,15 @@ export function isEmail(): Validator {
return {
type: "isEmail",
extends: [isString()],
convert: (value: any) => {
if (value === true) {
return "true";
} else if (value === false) {
return "false";
} else if (typeof value === "number") {
return value.toString();
}
},
check: (value: any) => {
if (value === null || value === undefined) return;
const regex =
@@ -141,7 +150,7 @@ export function isEmail(): Validator {
};
}
export function fulfillsRegex({regex}: {regex: RegExp}): Validator {
export function fulfillsRegex({ regex }: { regex: RegExp }): Validator {
return {
type: "fulfillsRegex",
extends: [isString()],