NumberSchema

Convenience methods for creating number schemas.

Extends

Methods

integer()

Require a number to be an integer.
Examples
const schema = vdn.number().integer()

vdn.attempt(5, schema)       // Result == 5 (valid)
vdn.attempt(5.3, schema)     // Throws ValidationError

Using data:

const schema = {
  type: 'number',
  integer: true
}

max(value)

Set the maximum value allowed.
Parameters:
Name Type Description
value number The maximum value allowed.
Examples
const schema = vdn.number().max(42)

vdn.attempt(42, schema)     // Result == 42 (valid)
vdn.attempt(43, schema)     // Throws ValidationError

Using data:

const schema = {
  type: 'number',
  max: 42
}

min(value)

Set the minimum value allowed.
Parameters:
Name Type Description
value number The minimum value allowed.
Examples
const schema = vdn.number().min(42)

vdn.attempt(42, schema)     // Result == 42 (valid)
vdn.attempt(41, schema)     // Throws ValidationError

Using data:

const schema = {
  type: 'number',
  min: 42
}