Members
(inner, constant) OPTIONS :Object
- Source:
Type:
- Object
Methods
(inner) validate(argObj, validators, options) → {Array}
- Description:
Validates each key-value entry in argObj using the validator functions in validators with matching keys.
For any failures, validate will console.error the reason.
- Source:
Example
const elements = {}
const name = 'michael'
const address = '12345 E. Street'
const [ isValid, results ] = validate(
{ elements, name, address },
{ elements: isArr, $default: isStr }
)
console.log(isValid) // false
console.log(results.elements.success) // false
Parameters:
Name | Type | Description |
---|---|---|
argObj |
Object | object, where keys are the name of the argument to validate, and value is its value |
validators |
Object | object, where keys match the argument and values are predicate functions (return true/false and are passed the arg with the same key).
- Use the |
options |
Object | contains |
Returns:
- An entry with two values [ success, results ].
- success: { Boolean } that is true if all arguments passed their validators, false otherwise
- results: {Object} that holds the validation results for each argument, keyed by the same keys as in argObj. For each result object, the properties are: { success, key, value, validator, reason }.
- success: { Boolean } that is true if all arguments passed their validators, false otherwise
- Type
- Array