Changed to constructor functions

This commit is contained in:
Sebastian Seedorf
2020-05-26 19:40:41 +02:00
parent 9fa06685ba
commit 836b1449bf
15 changed files with 281 additions and 168 deletions

View File

@@ -1,14 +1,32 @@
import { Validator, Args } from "../mod.ts";
export const isString: Validator = {
type: "isString",
check: (value: any) => {
if (value === null || value === undefined) return;
if (typeof value !== "string" && !(value instanceof String)) {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value has to be a string.`;
},
};
export function isString(): Validator {
return {
type: "isString",
check: (value: any) => {
if (value === null || value === undefined) return;
if (typeof value !== "string" && !(value instanceof String)) {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value has to be a string.`;
},
};
}
export function isURL(): Validator {
return {
type: "isURL",
extends: [isString()],
check: (value: any) => {
if (value === null || value === undefined) return;
if (value !== "http://google.com") {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value is not a valid URL.`;
},
};
}