- creators :
object
Creators allow for methods which create values during validation when a value is not supplied
- obey :
object
The main object for Obey; exposes the core API methods for standard use as well as the API for all other modules
- modifiers :
object
Modifiers allow for coercion/modification of a value present in the object when validation occurs
- rules :
object
Rules is responsible for determining the execution of schema definition properties during validation
- types :
object
Types determine and execute the appropriate validation to be performed on the data during validation
- getMessages(msgObjs) ⇒
Array.<string>
Compiles array items into string error messages
- ValidationError(message)
Creates ValidationError object for throwing
- validateByKeys(context, keyPrefix) ⇒
Promise.<Object>
Validates an object using the definition's
keys
property- validateByValues(context, keyPrefix) ⇒
Promise.<Object>
Validates an object using the definition's
values
property
Creators allow for methods which create values during validation when a value is not supplied
Kind: global namespace
- creators :
object
- .lib
- .execute(def, value) ⇒
function
- .add(name, fn)
Kind: static property of creators
Properties
Name | Type | Description |
---|---|---|
Library | Object |
of creators |
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
Returns: function
- The creator function
Param | Type | Description |
---|---|---|
def | Object |
The property configuration |
value | * |
The value being validated |
Adds a creator to the library
Kind: static method of creators
Param | Type | Description |
---|---|---|
name | string |
The name of the creator |
fn | function |
The creator's method |
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 :
object
- .rule(def) ⇒
Object
- .model(obj, [strict]) ⇒
Object
- .type(name, handler)
- .modifier(name, fn)
- .creator(name, fn)
- .rule(def) ⇒
Returns a composed rule from a definition object
Kind: static method of obey
Param | Type | Description |
---|---|---|
def | Object |
The rule definition |
Returns a composed model from a definition object
Kind: static method of obey
Param | Type | Default | Description |
---|---|---|---|
obj | Object |
The definition object | |
[strict] | boolean |
true |
Whether or not to enforce strict validation |
Creates and stores (or replaces) a type
Kind: static method of obey
Param | Type | Description |
---|---|---|
name | string |
The name of the type |
handler | Object | function |
The type method or object of methods |
Creates and stores a modifier
Kind: static method of obey
Param | Type | Description |
---|---|---|
name | string |
The modifier's name |
fn | function |
The method for the modifier |
Creates and stores a creator
Kind: static method of obey
Param | Type | Description |
---|---|---|
name | string |
The creator's name |
fn | function |
The method for the creator |
Modifiers allow for coercion/modification of a value present in the object when validation occurs
Kind: global namespace
- modifiers :
object
- .lib
- .execute(def, value) ⇒
function
- .add(name, fn)
Kind: static property of modifiers
Properties
Name | Type | Description |
---|---|---|
Library | Object |
of modifiers |
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
Returns: function
- The modifier function
Param | Type | Description |
---|---|---|
def | Object |
The property configuration |
value | * |
The value being validated |
Adds new modifier to the library
Kind: static method of modifiers
Param | Type | Description |
---|---|---|
name | string |
The name of the modifier |
fn | function |
The modifier's method |
Rules is responsible for determining the execution of schema definition properties during validation
Kind: global namespace
- rules :
object
- .props
- .makeValidate(def)
- .validate(def, data, [opts], [key], [errors], [rejectOnFail], [initData]) ⇒
Promise.<*>
- .build(def) ⇒
Object
- .getProps(def, data) ⇒
Array
Kind: static property of rules
Properties
Name | Type | Description |
---|---|---|
Validation | Object |
property setup and order of operations |
Binds rule definition in validate method
Kind: static method of rules
Param | Type | Description |
---|---|---|
def | Object |
The rule definition object |
Iterates over the properties present in the rule definition and sets the appropriate bindings to required methods
Kind: static method of 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 |
Adds new rule to the lib
Kind: static method of rules
Param | Type | Description |
---|---|---|
def | Object |
The rule definition |
Gets props list according to partial, required, and allowNull specifications
Kind: static method of rules
Param | Type | Description |
---|---|---|
def | Object |
The rule definition |
data | * |
The value being evaluated |
Types determine and execute the appropriate validation to be performed on the data during validation
Kind: global namespace
- types :
object
- .strategies
- .checkSubType(def) ⇒
Object
- .validate(def, value, key, errors, initData) ⇒
*
|Promise.<*>
- .add(name, handler)
- .check(context) ⇒
Promise.<*>
Kind: static property of types
Properties
Name | Type | Description |
---|---|---|
Contains | Object |
type strategies |
Checks for and applies sub-type to definition
Kind: static method of types
Param | Type | Description |
---|---|---|
def | Object |
The rule defintion |
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
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 |
Add (or override) a type in the library
Kind: static method of types
Param | Type | Description |
---|---|---|
name | string |
The name of the type |
handler | Object | function |
The type strategy method |
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
Returns: Promise.<*>
- Resolves with the provided data, possibly modified by the type strategy
Param | Type | Description |
---|---|---|
context | Object |
A type context |
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 |
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 |
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 |
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 |