UNPKG

@boomerang-io/utils

Version:

A library of reusable utilities and hooks for React webapps on the Boomerang platform.

34 lines (24 loc) 875 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addCustomValidator = addCustomValidator; exports.delCustomValidator = delCustomValidator; exports.getCustomValidator = getCustomValidator; var _yup = require("yup"); var CUSTOM_VALIDATORS = {}; function addCustomValidator(name, validator) { var binding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (binding !== false) { validator = validator.bind(binding); } CUSTOM_VALIDATORS[name] = validator; } function delCustomValidator(name) { delete CUSTOM_VALIDATORS[name]; } function getCustomValidator(name) { return CUSTOM_VALIDATORS[name]; } // Handle the case when we have an array of objects // but the previous instance of yup.shape is the yup.array addCustomValidator("yup.shape", (0, _yup.object)().shape, (0, _yup.object)());