UNPKG

@opbi/ncm-preset-package

Version:

the config preset for [package] used by ncm

30 lines (26 loc) 747 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /** * @typedef {(...args: any) => boolean} Validator */ /** * A decorator configurable to validate the param type of a function. * * @param {object} options - Config. * @param {Validator} options.validator - The validation method. * @param {boolean} [options.skip] - Whether to skip the check. * @returns {Function} - The decorated. */ const inputValidation = ({ validator = () => false, skip = false }) => action => (...args) => { if (skip) return action(...args); if (validator(...args)) return action(...args); throw Error('function validation failed'); }; var _default = inputValidation; exports.default = _default;