Spected Versions Save

Validation library

v0.7.2

1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/25th-floor/spected/compare/v0.7.1...v0.7.2

v0.7.0

6 years ago
  • Accept Functions as Input (#97) by @AutoSponge Spected now also accepts a function as input to validate against.

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)

  • Internal improvement (#94) by @cloud-walker
  • Typo Fixes by (#81) @yickli and (#96) @DavidSunny

v0.6.0

6 years ago

Added passing the field/key when errorMessage is a function (#89 by @Emilios1995)

v0.5.0

6 years ago

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)

v0.4.0

6 years ago

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.