str
The str extension contains string helper function for validation and comparison.
size
Returns the size/length of a string. If the supplied value isn't a string, -1 is returned.
Syntax
str.size(value)
Arguments
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.
Example(s)
// Check if value is a string and larger than 3 characters
str.size(scope.value) > 3
isString
Returns true
if the supplied value is a string, otherwise false
.
Syntax
str.isString(value)
Arguments
value
string
The value to check
Example(s)
str.isString('this is a string') // true
str.isString(99) // false (number)
isNullOrEmpty
Returns true
if the supplied value is null
/undefined
or an empty string (""
).
Syntax
str.isNullOrEmpty(value)
Arguments
value
string
The value to check
Example(s)
str.isNullOrEmpty(null) // true
str.isNullOrEmpty("") // true
str.isNullOrEmpty('this is a string') // false
isNotNullOrEmpty
Returns true
if the supplied value is a string and is not null
/undefined
or empty (""
).
Syntax
str.isNotNullOrEmpty(value)
Arguments
value
string
The value to check
Example(s)
str.isNotNullOrEmpty(null) // false
str.isNotNullOrEmpty("") // false
str.isNotNullOrEmpty('this is a string') // true
isEqual
Returns true
if the supplied values are strings with identical content, possible with different case.
Syntax
str.isEqual(s1, s2[, ignoreCase])
Arguments
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
)
Example(s)
str.isEqual('string value', 'string value') // true
str.isEqual('string value', 'other string value') // false
str.isEqual('string value', 'STRING VALUE') // false
str.isEqual('string value', 'STRING VALUE', true) // true
isEqualIgnoreCase
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)
Syntax
str.isEqualIgnoreCase(s1, s2)
Arguments
s1
string
The first string to compare for equality
s2
string
The second string to compare for equality
Example(s)
str.isEqualIgnoreCase('string value', 'string value') // true
str.isEqualIgnoreCase('string value', 'other string value') // false
str.isEqualIgnoreCase('string value', 'STRING VALUE') // true
matchAny
Returns true
if the supplied value match any of the supplied regular expressions (regex).
Syntax
str.matchAny(value, regex[,regex, ...])
Arguments
value
string
The value to match
regex
string | regex
One or more regular expressions used for matching.
Example(s)
// plain string regex
str.matchAny('value', 'v.*') // true
// typed regex (format: /regex/flags)
str.matchAny('value', /v.*/) // true
str.matchAny('value', /[0-9]{1,3}/) // false
// case insensitive match using i-flag
str.matchAny('value', /V.*/i) // true
Last updated