added number

This commit is contained in:
Sebastian Seedorf
2020-05-26 00:42:16 +02:00
parent 218e596ede
commit c59e4a6a50
5 changed files with 101 additions and 4 deletions

25
validators/number.ts Normal file
View File

@@ -0,0 +1,25 @@
import { Validator, Args } from "../mod.ts";
export const isNumber: Validator = {
type: "isNumber",
check: (value: any) => {
if (!Number.isFinite(value)) {
return {};
}
},
message: (value: any, args?: Args) => {
return `The value '${value && value.toString()}' has to be a number.`;
},
};
export const isInteger: Validator = {
type: "isInteger",
check: (value: any) => {
if (!Number.isInteger(value)) {
return {};
}
},
message: (value: any, args?: Args) => {
return `The value '${value && value.toString()}' has to be an integer.`;
},
};