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

@@ -8,63 +8,71 @@ import {
isBoolean,
} from "../mod.ts";
export const isRequired: Validator = {
type: "isRequired",
check: (value: any) => {
if (value === null || value === undefined) {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value is required.`;
},
};
export const isDefined: Validator = {
type: "isDefined",
check: (value: any) => {
if (value === undefined) {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value has to be defined.`;
},
};
export const isNotEmpty: Validator = {
type: "isNotEmpty",
check: async (value: any) => {
if (value === null || value === undefined) {
return {};
}
if ((await isString.check(value)) === undefined) {
if (/^\s*$/.test(value)) {
export function isRequired(): Validator {
return {
type: "isRequired",
check: (value: any) => {
if (value === null || value === undefined) {
return {};
}
return;
}
if ((await isNumber.check(value)) === undefined || Number.isNaN(value)) {
return;
}
if (await isSymbol.check(value) === undefined) {
return;
}
if (await isBoolean.check(value) === undefined) {
return;
}
if ((await isArray.check(value)) === undefined) {
if (value.length > 0) {
},
message: (value: any, args?: Args) => {
return `This value is required.`;
},
};
}
export function isDefined(): Validator {
return {
type: "isDefined",
check: (value: any) => {
if (value === undefined) {
return {};
}
},
message: (value: any, args?: Args) => {
return `This value has to be defined.`;
},
};
}
export function isNotEmpty(): Validator {
return {
type: "isNotEmpty",
check: async (value: any) => {
if (value === null || value === undefined) {
return {};
}
if ((await isString().check(value)) === undefined) {
if (/^\s*$/.test(value)) {
return {};
}
return;
}
if (
(await isNumber().check(value)) === undefined || Number.isNaN(value)
) {
return;
}
if (await isSymbol().check(value) === undefined) {
return;
}
if (await isBoolean().check(value) === undefined) {
return;
}
if ((await isArray().check(value)) === undefined) {
if (value.length > 0) {
return;
}
return {};
}
for (const key in value) {
return;
}
return {};
}
for (const key in value) {
return;
}
return {};
},
message: (value: any, args?: Args) => {
return `This value has to be non-empty.`;
},
};
},
message: (value: any, args?: Args) => {
return `This value has to be non-empty.`;
},
};
}