UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

32 lines (26 loc) 779 B
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkBQTT6CL2js = require('./chunk-BQTT6CL2.js'); // 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 = _chunkBQTT6CL2js.pipeValidators.call(void 0, this.rules)(value); return this; } then(opts) { if (this.result) { return this.result.fold(opts); } else { throw new (0, _chunkBQTT6CL2js.ValidationError)(`Validator failed to run - did you supply rules and use validate() first?`); } } }; exports.Validator = Validator; //# sourceMappingURL=chunk-EQXC6OKM.js.map