npm install @orioro/validate
ValidationErrorSpec
ValidationCase
ValidationError
ValidateOptions
validate(validationExpression, value, options)
validateThrow(validationExpression, value, options)
sequentialCases(cases)
parallelCases(cases)
allowValues(allowedValues, validation)
validationErrorSpec
{Object}code
{string}messsage
{string}
validationError
{Error}name
{string}message
{string}errors
{ValidationErrorSpec[]}value
{*}
Options for calling validate
options
{Object}interpreters
{Object}
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 aValidationErrorSpec
and should have the propertiescode
andmessage
-
an
Array
: is interpreted as an array ofValidationErrorSpec
objects -
null
: indicates that no errors were found -
validationExpression
{Expression} -
value
{*} -
options
{ValidateOptions} -
Returns: {null | ValidationErrorSpec[]}
Performs same validation process as validate
but if an error
is encountered throws a ValidationError
.
validationExpression
{Expression}value
{*}options
{ValidateOptions}
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}
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}
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}