UNPKG

@codeparticle/formal

Version:

A <2kb library for validating data of any kind

38 lines (26 loc) 1.15 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkUCMI2PE4js = require('./chunk-UCMI2PE4.js'); var _chunkL7GEZP4Ojs = require('./chunk-L7GEZP4O.js'); var _chunkJC7OWRM7js = require('./chunk-JC7OWRM7.js'); // src/rule.ts var Rule = class { constructor(opts) { this.check = (value) => { if (this.opts.condition(value)) { if (this.opts.transform) { return _chunkL7GEZP4Ojs.Success.of(this.opts.transform(value)); } return _chunkL7GEZP4Ojs.Success.of(value); } else { return typeof this.opts.message === `function` ? _chunkUCMI2PE4js.Fail.of(value, [this.opts.message(value)].flat()) : _chunkUCMI2PE4js.Fail.of(value, [this.opts.message].flat()); } }; this.opts = opts; } }; var createRule = (opts) => { return new Rule(opts); }; var withMessage = (message) => (rule) => new Rule(_chunkJC7OWRM7js.__spreadProps.call(void 0, _chunkJC7OWRM7js.__spreadValues.call(void 0, {}, rule.opts), { message })); exports.Rule = Rule; exports.createRule = createRule; exports.withMessage = withMessage; //# sourceMappingURL=chunk-YSLAWOV5.js.map