v0.2.0
Allow to extend the built-in Validator
class:
import { validate, Validator, ValidationError } from "validator-fluent";
class CoolValidator<K, V> extends Validator<K, V> {
constructor(key: K, value: V) {
super(key, value);
}
isLegit(): this {
if (!this.isEmpty && this.value !== "legit") {
this.errors.push("Not legit.");
}
return this;
}
}
const input = { name: "???" };
const [data, errors] = validate(input, CoolValidator, (value) => ({
name: value("name").notEmpty().isLegit(),
}));
if (Object.key(errors).length > 0) {
throw new ValidationError(errors);
}