@boomerang-io/utils
Version:
A library of reusable utilities and hooks for React webapps on the Boomerang platform.
27 lines (25 loc) • 869 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addCustomValidator = addCustomValidator;
exports.delCustomValidator = delCustomValidator;
exports.getCustomValidator = getCustomValidator;
var _yup = require("yup");
const CUSTOM_VALIDATORS = {};
function addCustomValidator(name, validator) {
let 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)());