UNPKG

@boomerang-io/utils

Version:

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

19 lines (18 loc) 665 B
import { object as yupObject } from "yup"; const CUSTOM_VALIDATORS = {}; export 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; } export function delCustomValidator(name) { delete CUSTOM_VALIDATORS[name]; } export 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", yupObject().shape, yupObject());