## Objects
object
Creators allow for methods which create values during validation when a value is not supplied
object
The main object for Obey; exposes the core API methods for standard use as well as the API for all other modules
object
Modifiers allow for coercion/modification of a value present in the object when validation occurs
object
Rules is responsible for determining the execution of schema definition properties during validation
object
Types determine and execute the appropriate validation to be performed on the data during validation
Array.<string>
Compiles array items into string error messages
Creates ValidationError object for throwing
Promise.<Object>
Validates an object using the definition's keys
property
Promise.<Object>
Validates an object using the definition's values
property
object
Creators allow for methods which create values during validation when a
value is not supplied
**Kind**: global namespace
* [creators](#creators) : object
* [.lib](#creators.lib)
* [.execute(def, value)](#creators.execute) ⇒ function
* [.add(name, fn)](#creators.add)
### creators.lib
**Kind**: static property of [creators](#creators)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| Library | Object
| of creators |
### creators.execute(def, value) ⇒ function
Execute method calls the appropriate creator and returns the method or
throws and error if the creator does not exist
**Kind**: static method of [creators](#creators)
**Returns**: function
- The creator function
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The property configuration |
| value | \*
| The value being validated |
### creators.add(name, fn)
Adds a creator to the library
**Kind**: static method of [creators](#creators)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The name of the creator |
| fn | function
| The creator's method |
## obey : object
The main object for Obey; exposes the core API methods for standard use as
well as the API for all other modules
**Kind**: global namespace
* [obey](#obey) : object
* [.rule(def)](#obey.rule) ⇒ Object
* [.model(obj, [strict])](#obey.model) ⇒ Object
* [.type(name, handler)](#obey.type)
* [.modifier(name, fn)](#obey.modifier)
* [.creator(name, fn)](#obey.creator)
### obey.rule(def) ⇒ Object
Returns a composed rule from a definition object
**Kind**: static method of [obey](#obey)
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The rule definition |
### obey.model(obj, [strict]) ⇒ Object
Returns a composed model from a definition object
**Kind**: static method of [obey](#obey)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| obj | Object
| | The definition object |
| [strict] | boolean
| true
| Whether or not to enforce strict validation |
### obey.type(name, handler)
Creates and stores (or replaces) a type
**Kind**: static method of [obey](#obey)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The name of the type |
| handler | Object
| function
| The type method or object of methods |
### obey.modifier(name, fn)
Creates and stores a modifier
**Kind**: static method of [obey](#obey)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The modifier's name |
| fn | function
| The method for the modifier |
### obey.creator(name, fn)
Creates and stores a creator
**Kind**: static method of [obey](#obey)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The creator's name |
| fn | function
| The method for the creator |
## modifiers : object
Modifiers allow for coercion/modification of a value present in the object
when validation occurs
**Kind**: global namespace
* [modifiers](#modifiers) : object
* [.lib](#modifiers.lib)
* [.execute(def, value)](#modifiers.execute) ⇒ function
* [.add(name, fn)](#modifiers.add)
### modifiers.lib
**Kind**: static property of [modifiers](#modifiers)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| Library | Object
| of modifiers |
### modifiers.execute(def, value) ⇒ function
Execute method calls the appropriate modifier and passes in the value or
throws an error if the modifier does not exist
**Kind**: static method of [modifiers](#modifiers)
**Returns**: function
- The modifier function
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The property configuration |
| value | \*
| The value being validated |
### modifiers.add(name, fn)
Adds new modifier to the library
**Kind**: static method of [modifiers](#modifiers)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The name of the modifier |
| fn | function
| The modifier's method |
## rules : object
Rules is responsible for determining the execution of schema definition
properties during validation
**Kind**: global namespace
* [rules](#rules) : object
* [.props](#rules.props)
* [.makeValidate(def)](#rules.makeValidate)
* [.validate(def, data, [opts], [key], [errors], [rejectOnFail], [initData])](#rules.validate) ⇒ Promise.<\*>
* [.build(def)](#rules.build) ⇒ Object
* [.getProps(def, data)](#rules.getProps) ⇒ Array
### rules.props
**Kind**: static property of [rules](#rules)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| Validation | Object
| property setup and order of operations |
### rules.makeValidate(def)
Binds rule definition in validate method
**Kind**: static method of [rules](#rules)
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The rule definition object |
### rules.validate(def, data, [opts], [key], [errors], [rejectOnFail], [initData]) ⇒ Promise.<\*>
Iterates over the properties present in the rule definition and sets the
appropriate bindings to required methods
**Kind**: static method of [rules](#rules)
**Returns**: Promise.<\*>
- Resolves with the resulting data, with any defaults, creators, and modifiers applied.
Rejects with a ValidationError if applicable.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| def | Object
| | The rule definition object |
| data | \*
| | The data (value) to validate |
| [opts] | Object
| {partial: false}
| Specific options for validation process |
| [key] | string
| null
| null
| Key for tracking parent in nested iterations |
| [errors] | Array.<{type: string, sub: string, key: string, value: \*, message: string}>
| []
| An error array to which any additional error objects will be added. If not specified, a new array will be created. |
| [rejectOnFail] | boolean
| true
| If true, resulting promise will reject if the errors array is not empty; otherwise ValidationErrors will not cause a rejection |
| [initData] | Object
| null
|
| Initial data object |
### rules.build(def) ⇒ Object
Adds new rule to the lib
**Kind**: static method of [rules](#rules)
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The rule definition |
### rules.getProps(def, data) ⇒ Array
Gets props list according to partial, required, and allowNull specifications
**Kind**: static method of [rules](#rules)
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The rule definition |
| data | \*
| The value being evaluated |
## types : object
Types determine and execute the appropriate validation to be performed on the
data during validation
**Kind**: global namespace
* [types](#types) : object
* [.strategies](#types.strategies)
* [.checkSubType(def)](#types.checkSubType) ⇒ Object
* [.validate(def, value, key, errors, initData)](#types.validate) ⇒ \*
| Promise.<\*>
* [.add(name, handler)](#types.add)
* [.check(context)](#types.check) ⇒ Promise.<\*>
### types.strategies
**Kind**: static property of [types](#types)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| Contains | Object
| type strategies |
### types.checkSubType(def) ⇒ Object
Checks for and applies sub-type to definition
**Kind**: static method of [types](#types)
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The rule defintion |
### types.validate(def, value, key, errors, initData) ⇒ \*
| Promise.<\*>
Sets up the `fail` method and handles `empty` or `undefined` values. If neither
empty or undefined, calls the appropriate `type` and executes validation
**Kind**: static method of [types](#types)
**Returns**: \*
| Promise.<\*>
- The value if empty or undefined, check method if value requires type validation
| Param | Type | Description |
| --- | --- | --- |
| def | Object
| The property configuration |
| value | \*
| The value being validated |
| key | string
| The key name of the property |
| errors | Array.<{type: string, sub: (string\|number), key: string, value: \*, message: string}>
| An error array to which any additional error objects will be added |
| initData | Object
| Initial data object |
### types.add(name, handler)
Add (or override) a type in the library
**Kind**: static method of [types](#types)
| Param | Type | Description |
| --- | --- | --- |
| name | string
| The name of the type |
| handler | Object
| function
| The type strategy method |
### types.check(context) ⇒ Promise.<\*>
Ensures that the strategy exists, loads if not already in memory, then ensures
subtype and returns the applied type strategy
**Kind**: static method of [types](#types)
**Returns**: Promise.<\*>
- Resolves with the provided data, possibly modified by the type strategy
| Param | Type | Description |
| --- | --- | --- |
| context | Object
| A type context |
## getMessages(msgObjs) ⇒ Array.<string>
Compiles array items into string error messages
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| msgObjs | Array.<{type: string, sub: (string\|number), key: string, value: \*, message: string}>
| Original array of error message objects |
## ValidationError(message)
Creates ValidationError object for throwing
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| message | Array.<{type: string, sub: (string\|number), key: string, value: \*, message: string}>
| Raw array of error objects |
## validateByKeys(context, keyPrefix) ⇒ Promise.<Object>
Validates an object using the definition's `keys` property
**Kind**: global function
**Returns**: Promise.<Object>
- Resolves with the final object
| Param | Type | Description |
| --- | --- | --- |
| context | Object
| An Obey type context |
| keyPrefix | string
| A prefix to include before the key in an error message |
## validateByValues(context, keyPrefix) ⇒ Promise.<Object>
Validates an object using the definition's `values` property
**Kind**: global function
**Returns**: Promise.<Object>
- Resolves with the final object
| Param | Type | Description |
| --- | --- | --- |
| context | Object
| An Obey type context |
| keyPrefix | string
| A prefix to include before the key in an error message |