Open WPS Platform

ZOO.String

Contains convenience methods for string manipulation:

Functions and Properties

NAME DESCRIPTION
startsWith Test whether a string starts with another string.
contains Test whether a string contains another string.
trim Removes leading and trailing whitespace characters from a string.
camelize Camel-case a hyphenated string.
tokenRegEx Used to find tokens in a string.
numberRegEx Used to test strings as numbers.
isNumeric Determine whether a string contains only a numeric value.
numericIf Converts a string that appears to be a numeric value into a number.
startsWith
startsWith: function(str,sub)

Test whether a string starts with another string.

Parameters

str {String} The string to test.
sub {Sring} The substring to look for.

Returns

{Boolean} The first string starts with the second.

contains
contains: function(str,sub)

Test whether a string contains another string.

Parameters

str {String} The string to test.
sub {String} The substring to look for.

Returns

{Boolean} The first string contains the second.

trim
trim: function(str)

Removes leading and trailing whitespace characters from a string.

Parameters

str {String} The (potentially) space-padded string. This string is not modified.

Returns

{String} A trimmed version of the string with all leading and trailing spaces removed.

camelize
camelize: function(str)

Camel-case a hyphenated string. Ex. “chicken-head” becomes “chickenHead”, and “-chicken-head” becomes “ChickenHead”.

Parameters

str {String} The string to be camelized. The original is not modified.

Returns

{String} The string, camelized

tokenRegEx
Used to find tokens in a string. Examples: ${a}, ${a.b.c}, ${a-b}, ${5}
numberRegEx
Used to test strings as numbers.
isNumeric
isNumeric: function(value)

Determine whether a string contains only a numeric value.

Examples

ZOO.String.isNumeric("6.02e23") // true
ZOO.String.isNumeric("12 dozen") // false
ZOO.String.isNumeric("4") // true
ZOO.String.isNumeric(" 4 ") // false

Returns

{Boolean} String contains only a number.

numericIf
numericIf: function(value)

Converts a string that appears to be a numeric value into a number.

Returns

{Number|String} a Number if the passed value is a number, a String otherwise.