String Class
Pollyfils for often used functionality for Strings Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
Item Index
Methods
contains
-
substring
-
[caseInsensitive=false]
Checks whether the substring is part if this String. Alias for (String.indexOf(substring) > -1)
Parameters:
Returns:
whether the substring is found
endsWith
-
test
-
[caseInsensitive=false]
Checks if the string ends with the value specified by test
Parameters:
Returns:
whether the string ends with test
parsable
()
Boolean
Checks if the string can be parsed into a number when using parseInt()
Returns:
whether the string is parsable
replace
-
search
-
replacement
-
[caseInsensitive=false]
Replaces search-characters by a replacement. Replaces only the firts occurence. Does not alter the String itself, but returns a new String with the replacement.
Parameters:
Returns:
new String with the replacement
replaceAll
-
search
-
replacement
-
[caseInsensitive=false]
Replaces search-characters by a replacement. Replaces all occurences. Does not alter the String itself, but returns a new String with the replacements.
Parameters:
Returns:
new String with the replacements
startsWith
-
test
-
[caseInsensitive=false]
Checks if the string starts with the value specified by test
Parameters:
Returns:
whether the string starts with test
substitute
-
obj
Performs {placeholder}
substitution on a string. The object passed
provides values to replace the {placeholder}
s.
{placeholder}
token names must match property names of the object.
{placeholder}
tokens that are undefined on the object map will be removed.
Parameters:
-
obj
ObjectObject containing replacement values.
Returns:
the substitute result.
Example:
var greeting = '{message} {who}!'; greeting.substitute({message: 'Hello'}); // results into 'Hello !'
toDate
()
Date | Null
Returns a ISO-8601 Date-object build by the String's value.
If the String-value doesn't match ISO-8601, null
will be returned.
ISO-8601 Date's are generated by JSON.stringify(), so it's very handy to be able to reconvert them.
Returns:
the Date represented by the String's value or null when invalid
Example:
var birthday = '2010-02-10T14:45:30.000Z'; birthday.toDate(); // --> Wed Feb 10 2010 15:45:30 GMT+0100 (CET)
trim
()
String
Generated the string without any white-spaces at the start or end.
Returns:
new String without leading and trailing white-spaces
trimLeft
()
String
Generated the string without any white-spaces at the beginning.
Returns:
new String without leading white-spaces
trimRight
()
String
Generated the string without any white-spaces at the end.
Returns:
new String without trailing white-spaces
validateBoolean
()
Boolean
Validates if the String's value represents a valid boolean.
Returns:
whether the String's value is a valid boolean.
validateDate
()
Boolean
Validates if the String's value represents a valid Date.
Returns:
whether the String's value is a valid Date object.
validateEmail
()
Boolean
Validates if the String's value represents a valid emailaddress.
Returns:
whether the String's value is a valid emailaddress.
validateFloat
-
[comma]
Validates if the String's value represents a valid floated number.
Parameters:
-
[comma]
Boolean optionalwhether to use a comma as decimal separator instead of a dot
Returns:
whether the String's value is a valid floated number.
validateHexaColor
-
[alpha=false]
Validates if the String's value represents a hexadecimal color.
Parameters:
-
[alpha=false]
Boolean optionalwhether to accept alpha transparancy
Returns:
whether the String's value is a valid hexadecimal color.
validateNumber
()
Boolean
Validates if the String's value represents a valid integer number.
Returns:
whether the String's value is a valid integer number.