UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

38 lines (36 loc) 905 B
import { Fail } from "./chunk-PTDFSPAW.mjs"; import { Success } from "./chunk-ULL3TXJG.mjs"; import { __spreadProps, __spreadValues } from "./chunk-IZSPT6RB.mjs"; // src/rule.ts var Rule = class { constructor(opts) { this.check = (value) => { if (this.opts.condition(value)) { if (this.opts.transform) { return Success.of(this.opts.transform(value)); } return Success.of(value); } else { return typeof this.opts.message === `function` ? Fail.of(value, [this.opts.message(value)].flat()) : Fail.of(value, [this.opts.message].flat()); } }; this.opts = opts; } }; var createRule = (opts) => { return new Rule(opts); }; var withMessage = (message) => (rule) => new Rule(__spreadProps(__spreadValues({}, rule.opts), { message })); export { Rule, createRule, withMessage }; //# sourceMappingURL=chunk-DDICIM7S.mjs.map