mv
Script extension for multi value validation and comparison.
All functions operating on multi values will convert supplied value(s) to multi value if not already (see mv.from(value)
)
In JavaScript multi values are represented as arrays.
mv.from
Converts a value to a multi value if not already.
Handles the following types of input values:
arrays (returned as is)
json arrays (parsed to array)
single values of any types (added as first element to new array)
Syntax
mv.from(value)
Arguments
value
any
The value to convert to multi value
Example(s)
mv.length
Returns the length of the supplied multi value.
Syntax
mv.length(value)
Arguments
value
any
The multi value whose length is to be calculated and returned.
Example(s)
mv.contains
Returns true
if the supplied multi value contains the supplied expected value, possibly ignoring the case (if values are strings).
Note: This function works exactly like mv.containsAny
but with support for only one expected value.
Syntax
mv.contains(value, expected[, ignoreCase])
Arguments
value
any
The multi value whose content is to be asserted.
expected
any
Value expected to be contained in value
ignoreCase
boolean
Flag turning on string case insensitivity (default: false
)
Example(s)
mv.containsAny
Returns true
if the supplied multi value contains at least one of the supplied expected values, possibly ignoring the case (if values are strings).
Syntax
mv.containsAny(value, expected[, expected, ...][, ignoreCase])
Arguments
value
any
The multi value whose content is to be asserted.
expected
any
One or more values expected to be contained in value
ignoreCase
boolean
Flag turning on string case insensitivity (default: false
)
Example(s)
mv.containsAll
Returns true
if the supplied multi value contains all of the supplied expected values, possibly ignoring the case (if values are strings).
Syntax
mv.containsAll(value, expected[, expected, ...][, ignoreCase])
Arguments
value
any
The multi value whose content is to be asserted.
expected
any
One or more values expected to be contained in value
ignoreCase
boolean
Flag turning on string case insensitivity (default: false
)
Example(s)
mv.matchAny
Returns true
if at least one value in the supplied multi value matches one or more of the supplied regex's.
Regex may be supplied as strings, regex-literals or RegExp objects.
Note: Case-insensitivity is controlled by regex flag ('i'
).
Syntax
mv.matchAny(value, regex [,regex, ...])
Arguments
value
any
The multi value whose content is to be matched.
expected
any
One or more regex to match against value.
Example(s)
mv.equals
Returns true
if the supplied multi values has exactly same content.
Syntax
mv.equals(mv1, mv2)
Arguments
mv1
any
The multi value whose content is to be matched.
mv2
any
One or more regex to match against value.
Example(s)
mv.isEmpty
Returns true
if the supplied multi value is not null/undefined and is empty.
Syntax
mv.isEmpty(value)
Arguments
value
any
The multi value to assert
Example(s)
mv.isNotEmpty
Returns true
if the supplied multi value is not null/undefined and is not empty (has one or more elements).
Syntax
mv.isNotEmpty(value)
Arguments
value
any
The multi value to assert
Example(s)
mv.isNullOrEmpty
Returns true
if the supplied multi value is null/undefined or is empty.
Syntax
mv.isNullOrEmpty(value)
Arguments
value
any
The multi value to assert
Example(s)
mv.isNotNullOrEmpty
Returns true
if the supplied multi value is not null/undefined and is not empty (has one or more element).
Syntax
mv.isNotNullOrEmpty(value)
Arguments
value
any
The multi value to assert
Example(s)
Last updated