diff --git a/README.md b/README.md index 50deda5..e6fad9f 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,16 @@ I want to validate an object and get failure messages for each field: import { errors, isNaturalNumberString } from "reviewed"; const pagination = (url: URL): void => { - const page = url.searchParams.get("page"); - const size = url.searchParams.get("size"); - - const { valid, parsed, error } = merge({ - page: isNaturalNumberString(page), - size: isNaturalNumberString(size), - }); + const { valid, parsed, error } = validateWith( + { + page: isNaturalNumberString, + size: isNaturalNumberString, + }, + { + page: url.searchParams.get("page"), + size: url.searchParams.get("size"), + } + ); if (valid) { console.log(parsed); @@ -126,7 +129,7 @@ export const isNaturalNumber: Validator = (input: unknown) => { isIntegerCheck.parsed > 0, input, input, - "Not a natural number", + "Not a natural number" ); }; ``` @@ -196,7 +199,7 @@ const isNumber: Validator = (input: unknown) => typeof input === "number" && isFinite(input), input, input, - "Not a number", + "Not a number" ); ``` @@ -215,7 +218,7 @@ const isObject: Validator = (input: unknown) => typeof input === "object" && input !== null, input, input, - "Not an object", + "Not an object" ); ``` @@ -229,13 +232,13 @@ const isObject: Validator = (input: unknown) => ```ts const isRecord: Validator> = ( - input: unknown, + input: unknown ) => validateIf( isObject(input).valid && !isArray(input).valid, input, input, - "Not a record", + "Not a record" ); ``` diff --git a/src/models/regexes/RegexValidator.model.ts b/src/models/regexes/RegexValidator.model.ts index 72553fb..341332c 100644 --- a/src/models/regexes/RegexValidator.model.ts +++ b/src/models/regexes/RegexValidator.model.ts @@ -5,5 +5,5 @@ import { Validated } from "../validation/Validated.model"; * @typeParam T - the validated type */ export type RegexValidator = ( - obj: unknown, + input: unknown, ) => Validated>; diff --git a/src/models/validation/Validator.model.ts b/src/models/validation/Validator.model.ts index e0b45f2..5523008 100644 --- a/src/models/validation/Validator.model.ts +++ b/src/models/validation/Validator.model.ts @@ -6,5 +6,5 @@ import { ValidationErrors } from "./ValidationErrors.model"; * @typeParam U - the validation errors type */ export type Validator = string> = ( - obj: unknown, + input: unknown, ) => Validated;