mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
27 lines
714 B
JavaScript
27 lines
714 B
JavaScript
import validateFptf from 'validate-fptf';
|
|
const {defaultValidators} = validateFptf;
|
|
import anyOf from 'validate-fptf/lib/any-of.js';
|
|
|
|
import validators from './validators.js';
|
|
|
|
const createValidateFptfWith = (cfg, customValidators = {}) => {
|
|
const val = Object.assign({}, defaultValidators);
|
|
for (let key of Object.keys(validators)) {
|
|
val[key] = validators[key](cfg);
|
|
}
|
|
Object.assign(val, customValidators);
|
|
|
|
const validateFptfWith = (t, item, allowedTypes, name) => {
|
|
if ('string' === typeof allowedTypes) {
|
|
val[allowedTypes](val, item, name);
|
|
} else {
|
|
anyOf(allowedTypes, val, item, name);
|
|
}
|
|
t.pass(name + ' is valid');
|
|
};
|
|
return validateFptfWith;
|
|
};
|
|
|
|
export {
|
|
createValidateFptfWith,
|
|
};
|