UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

32 lines (30 loc) 664 B
import { ValidationError, pipeValidators } from "./chunk-BWJJJL7W.mjs"; // src/validation.ts var Validator = class { constructor(...rules) { this.rules = []; this.result = null; this.rules = rules.flat(); } static of(...rules) { return new Validator(...rules); } validate(value) { this.result = pipeValidators(this.rules)(value); return this; } then(opts) { if (this.result) { return this.result.fold(opts); } else { throw new ValidationError(`Validator failed to run - did you supply rules and use validate() first?`); } } }; export { Validator }; //# sourceMappingURL=chunk-IWICEORL.mjs.map