@orioro/validate v0.0.2
node-validate
npm install @orioro/validateUse cases
API
ValidationErrorSpecValidationCaseValidationErrorValidateOptionsvalidate(validationExpression, value, options)validateThrow(validationExpression, value, options)sequentialCases(cases)parallelCases(cases)allowValues(allowedValues, validation)prohibitValues(prohibitedValues, error, validation)
ValidationErrorSpec
validationErrorSpec{Object}code{string}messsage{string}
ValidationCase
ValidationError
validationError{Error}name{string}message{string}errors{ValidationErrorSpec[]}value{*}
ValidateOptions
Options for calling validate
options{Object}interpreters{Object}
validate(validationExpression, value, options)
Executes a validation expression against the given value.
Returns either an Array of ValidationErrorSpec objects
or null (which indicates there were no errors found and the
value is valid).
The expression may return one of these values:
- a 
string: is interpreted as an error code and will be converted to aValidationErrorSpec(e.g.'SOME_VALIDATION_ERROR'becomes{ code: 'SOME_VALIDATION_ERROR' }) - an 
object: is interpreted as aValidationErrorSpecand should have the propertiescodeandmessage - an 
Array: is interpreted as an array ofValidationErrorSpecobjects null: indicates that no errors were foundvalidationExpression{Expression}value{*}options{ValidateOptions}- Returns: {null | ValidationErrorSpec[]}
 
validateThrow(validationExpression, value, options)
Performs same validation process as validate but if an error
is encountered throws a ValidationError.
validationExpression{Expression}value{*}options{ValidateOptions}
sequentialCases(cases)
Takes an array of ValidationCases and returns a ValidationExpression
to be used with either validate or validateThrow.
The returned expression evaluates each case sequentially
and if any of the cases returns a non-null value, the
validation is interrupted and remaining cases are not evaluated.
cases{ValidationCase[]}- Returns: {ValidationExpression}
 
parallelCases(cases)
Takes an array of ValidationCases and returns a ValidationExpression
to be used with either validate or validateThrow.
The returned expression evaluates all cases in parallel and returns an array of all errors found.
cases{ValidationCase[]}- Returns: {ValidationExpression}
 
allowValues(allowedValues, validation)
Wraps the given validationExpression so that it returns
null (no error) if the value equals any of the specified
allowedValues.
allowedValues{*[]}validation{ValidationExpression}- Returns: {ValidationExpression}
 
prohibitValues(prohibitedValues, error, validation)
Wraps the given validationExpression so that it returns
the given error if the value specified equals any of the
specified prohibitedValues
prohibitedValues{*[]}error{ValidationErrorSpec | string}validation{ValidationExpression}- Returns: {ValidationExpression}