Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 9x 7x 9x 12x | import { Validator, ValidationResult } from "./_types";
/**
* An helper function that executes a {@link Validator} with a default
* {@link ValidationContext}.
*
* @exmaple
* ```ts
* const isStringValidator = valueValidator(isString, "must be a string");
* const validationResult = validate(isStringValidator)("");
* console.log(validationResult); // []
* ```
*
* @typeParam T - the type of the value to validate
* @param validator - the {@link Validator} to execute
* @returns the {@link ValidationResult}
*/
export const validate =
<T>(validator: Validator<T, T, unknown>) =>
(value: T): ValidationResult => {
return validator(value, {
path: "$",
root: value,
parent: undefined,
shortCircuit: false,
});
};
|