UNPKG

validx

Version:
23 lines 675 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.func = void 0; const DEFAULT_MESSAGE = 'This field is not valid'; /** * Simple way to run a function and return an error message. * * @param rule * @returns {(opts:any)=>boolean|string} */ const func = (rule, msg = DEFAULT_MESSAGE) => { if (!rule) { throw new TypeError('Expected a function or a configuration object, got ' + rule); } return (opts) => { if (typeof rule === 'function') { return rule(opts) || msg; } return rule.fn(opts) || rule.msg || msg; }; }; exports.func = func; //# sourceMappingURL=funcValidator.js.map