Predicates and other script evaluation (like ScriptEvalValve) has support for extensions. An extension is a library of functions in a namespace.
The following extension are available by default:
str (common string operations)
mv (multi-value support)
dbg (debug)
Ipv4 (IPv4 address matching)
Extension containing debug utilities
Describes a value, prints the result to stdout and returns the value.
Output will contain:
Type ('string'
, 'array'
, 'object'
, 'number'
, etc)
Value (concatenated to 32 chars)
Length (if applicable)
If value is an array (when type is 'object'
)
If value is JSON (when type is 'string'
)
JSON-type (when parsed)
JSON-length (when parsed)
dbg.describe(value[, label])
Name | Type | Description |
---|---|---|
value
any
The value to describe.
The str extension contains string helper function for validation and comparison.
Returns the size/length of a string. If the supplied value isn't a string, -1 is returned.
str.size(value)
Name | Type | Description |
---|---|---|
Returns true
if the supplied value is a string, otherwise false
.
str.isString(value)
Returns true
if the supplied value is null
/undefined
or an empty string (""
).
str.isNullOrEmpty(value)
Returns true
if the supplied value is a string and is not null
/undefined
or empty (""
).
str.isNotNullOrEmpty(value)
Returns true
if the supplied values are strings with identical content, possible with different case.
str.isEqual(s1, s2[, ignoreCase])
Returns true
if the supplied values are strings with identical content, always ignoring different case.
This function is equivalent to str.isEqual(s1, s2, true)
str.isEqualIgnoreCase(s1, s2)
Returns true
if the supplied value match any of the supplied regular expressions (regex).
str.matchAny(value, regex[,regex, ...])
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.
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)
mv.from(value)
Name | Type | Description |
---|---|---|
Returns the length of the supplied multi value.
mv.length(value)
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.
mv.contains(value, expected[, ignoreCase])
Returns true
if the supplied multi value contains at least one of the supplied expected values, possibly ignoring the case (if values are strings).
mv.containsAny(value, expected[, expected, ...][, ignoreCase])
Returns true
if the supplied multi value contains all of the supplied expected values, possibly ignoring the case (if values are strings).
mv.containsAll(value, expected[, expected, ...][, ignoreCase])
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'
).
mv.matchAny(value, regex [,regex, ...])
Returns true
if the supplied multi values has exactly same content.
mv.equals(mv1, mv2)
Returns true
if the supplied multi value is not null/undefined and is empty.
mv.isEmpty(value)
Returns true
if the supplied multi value is not null/undefined and is not empty (has one or more elements).
mv.isNotEmpty(value)
Returns true
if the supplied multi value is null/undefined or is empty.
mv.isNullOrEmpty(value)
Returns true
if the supplied multi value is not null/undefined and is not empty (has one or more element).
mv.isNotNullOrEmpty(value)
Extension for asserting IPv4 addresses
Returns true is the supplied IP belongs to the supplied subnet in CIDR notation.
Use this function to assert that a client belongs to a specific network.
IP-addresses should be octets in dotted-string format: '192.168.30.5'
Subnets are specified using CIDR notation containing an ip and the length of the subnet mask: '10.1.1.0/24'
ipv4.isInSubnet(ip, subnet)
Name | Type | Description |
---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
value
string
The string whose length is calculated and returned. If empty, 0
is returned. If null, undefined or not a string, -1
is returned.
value
string
The value to check
value
string
The value to check
value
string
The value to check
s1
string
The first string to compare for equality
s2
string
The second string to compare for equality
ignoreCase
boolean
Flag turning on case-insensitive compare (default: false
)
s1
string
The first string to compare for equality
s2
string
The second string to compare for equality
value
string
The value to match
regex
string | regex
One or more regular expressions used for matching.
value
any
The value to convert to multi value
value
any
The multi value whose length is to be calculated and returned.
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
)
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
)
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
)
value
any
The multi value whose content is to be matched.
expected
any
One or more regex to match against value.
mv1
any
The multi value whose content is to be matched.
mv2
any
One or more regex to match against value.
value
any
The multi value to assert
value
any
The multi value to assert
value
any
The multi value to assert
value
any
The multi value to assert
|
| The IP-address in octets |
|
| The subnet in CIDR-notation |