UNPKG

@data-driven-forms/react-form-renderer

Version:

React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.

24 lines 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function composeValidators(validators) { if (validators === void 0) { validators = []; } return function (value, allValues, meta) { var initialValidator = validators[0], sequenceValidators = validators.slice(1); var resolveValidator = function (error, validator) { if (error) { return error; } if (typeof validator !== 'function') { return undefined; } return validator(value, allValues, meta); }; var result = resolveValidator(undefined, initialValidator); if (result === null || result === void 0 ? void 0 : result.then) { return result.then(function () { return sequenceValidators.reduce(resolveValidator, undefined); }).catch(function (error) { return error; }); } return sequenceValidators.reduce(resolveValidator, result); }; } exports.default = composeValidators; //# sourceMappingURL=compose-validators.js.map