Validation library
Full Changelog: https://github.com/25th-floor/spected/compare/v0.7.1...v0.7.2
const verify = validate(a => a, a => a)
const validationRules = {
name: nameValidationRule,
}
const input = {name: 'foobarbaz'}
const result = verify(validationRules, key => key ? ({...input, [key]: ''}) : input)
deepEqual({name: ['Name should not be empty.']}, result)
Added passing the field/key when errorMessage is a function (#89 by @Emilios1995)
Spected handles any array input now. (See #85)
The input can be
{ values: ['a', 'b'] }
or
{ values: [{a: 1}, {a: 2}] }
or
{ values: [1, 'a', {a: 1}] }
.
Spected runs any array input against a given spec. This also means that the defined predicates have to know how to handle the given input.
const userSpec = [
[
items => all(isLengthGreaterThan(5), items),
'Every item must have have at least 6 characters!'
]
]
const validationRules = {
id: [[ notEmpty, notEmptyMsg('id') ]],
users: userSpec,
}
const input = {
id: 4,
users: ['foobar', 'foobarbaz']
}
spected(validationRules, input)
Added dynamic input validations. Spected runs a defined spec against every property or item for the provided input array or object.
Handles a collection of items to validate against.
Handles an object with an arbitrary number of properties.