lion/packages/validate/src/isValidatorApplied.js
2019-05-16 10:39:57 +02:00

18 lines
725 B
JavaScript

/**
* TODO: refactor validators to classes, putting needed meta info on instance.
* Note that direct function comparison (Validator[0] === minDate) doesn't work when code
* is transpiled
* @param {String} name - a name like minDate, maxDate, minMaxDate
* @param {Function} fn - the validator function to execute provided in [fn, param, config]
* @param {Function} requiredSignature - arguments needed to execute fn without failing
* @returns {Boolean} - whether the validator (name) is applied
*/
export function isValidatorApplied(name, fn, requiredSignature) {
let result;
try {
result = Object.keys(fn(new Date(), requiredSignature))[0] === name;
} catch (e) {
result = false;
}
return result;
}