Contains convenience methods for string manipulation:
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: function(str,sub)
Test whether a string starts with another string.
Parameters
Returns
{Boolean} The first string starts with the second.
contains: function(str,sub)
Test whether a string contains another string.
Parameters
Returns
{Boolean} The first string contains the second.
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: 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
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: 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.