State

Holds state during validation.

Members

(readonly) context :Object

Context used for validation.

(readonly) errors :Array.<Object>

The current list of errors.

(readonly) options :Object

Returns options used during validation. Currently unused. Possible future use.

(readonly) path :Array.<string>

Returns the path of this state.
Example
state.path -> []                           // At root level
state.path -> [ 'someObject', 'someKey' ]  // At 'someObject.someKey'

Methods

clone(overrides) → {State}

Clone this state and override properties.
Parameters:
Name Type Description
overrides Object Properties to override on the cloned state.
Returns:
Type
State
New state with overriden properties.

error()

Add a new error to this state.

substate(name) → {State}

Build a new substate and return it.
Parameters:
Name Type Description
name string The name of the new child state.
Returns:
Type
State
New substate.
Example
substate('a')               -> path == [ 'a' ]      // At 'a'
substate('a').substate('b') -> path == [ 'a', 'b' ] // At 'a.b'
substate('a').substate(1)   -> path == [ 'a', 1 ]   // At 'a[1]'

validate()

Validate a value against a schema. See VDN#validate.