ObjectSchema

Convenience methods for creating object schemas.

Extends

Methods

entries(entries)

Require each object entry to match a given schema.
Parameters:
Name Type Description
entries Object.<string, AnySchema> Object that holds schemas for each object entry.
Examples
const schema = vdn.object().entries({
  id: vdn.number().integer(),
  mail: vdn.string().email(),
})

vdn.attempt({ id:2,   mail:'a@b.com' }, schema) // Valid
vdn.attempt({ id:2.3, mail:'a@b.com' }, schema) // Throws ValidationError
vdn.attempt({ id:2,   mail:'b.com'   }, schema) // Throws ValidationError

Using data:

const schema = {
  type: 'object',
  entries: {
    value: {
      id: {
        type: 'number',
        integer: true
      },
      mail: {
        type: 'string',
        email: true
      }
    }
  }
}