the compact javascript framework
in partnership with mediatemple
Contains String prototypes.
MIT-style license.
String.js | Contains String prototypes. |
String | A collection of The String Object prototype methods. |
Properties | |
test | Tests a string with a regular expression. |
toInt | parses a string to an integer. |
toFloat | parses a string to an float. |
camelCase | Converts a hiphenated string to a camelcase string. |
hyphenate | Converts a camelCased string to a hyphen-ated string. |
capitalize | Converts the first letter in each word of a string to Uppercase. |
trim | Trims the leading and trailing spaces off a string. |
clean | trims (String.trim) a string AND removes all the double spaces in a string. |
rgbToHex | Converts an RGB value to hexidecimal. |
hexToRgb | Converts a hexidecimal color value to RGB. |
contains | checks if the passed in string is contained in the String. |
escapeRegExp | Returns string with escaped regular expression characters |
rgbToHex | see String.rgbToHex, but as an array method. |
hexToRgb | same as String.hexToRgb, but as an array method. |
A collection of The String Object prototype methods.
Properties | |
test | Tests a string with a regular expression. |
toInt | parses a string to an integer. |
toFloat | parses a string to an float. |
camelCase | Converts a hiphenated string to a camelcase string. |
hyphenate | Converts a camelCased string to a hyphen-ated string. |
capitalize | Converts the first letter in each word of a string to Uppercase. |
trim | Trims the leading and trailing spaces off a string. |
clean | trims (String.trim) a string AND removes all the double spaces in a string. |
rgbToHex | Converts an RGB value to hexidecimal. |
hexToRgb | Converts a hexidecimal color value to RGB. |
contains | checks if the passed in string is contained in the String. |
escapeRegExp | Returns string with escaped regular expression characters |
rgbToHex | see String.rgbToHex, but as an array method. |
hexToRgb | same as String.hexToRgb, but as an array method. |
Tests a string with a regular expression.
regex | a string or regular expression object, the regular expression you want to match the string with |
params | optional, if first parameter is a string, any parameters you want to pass to the regex (‘g’ has no effect) |
true if a match for the regular expression is found in the string, false if not. See http://developer.mozilla.org- /en- /docs- /Core_JavaScript_1.5_Reference:Objects:RegExp:test
"I like cookies".test("cookie"); // returns true "I like cookies".test("COOKIE", "i") // ignore case, returns true "I like cookies".test("cake"); // returns false
parses a string to an integer.
either an int or “NaN” if the string is not a number.
var value = "10px".toInt(); // value is 10
parses a string to an float.
either a float or “NaN” if the string is not a number.
var value = "10.848".toFloat(); // value is 10.848
Converts a hiphenated string to a camelcase string.
"I-like-cookies".camelCase(); //"ILikeCookies"
the camel cased string
Converts a camelCased string to a hyphen-ated string.
"ILikeCookies".hyphenate(); //"I-like-cookies"
Converts the first letter in each word of a string to Uppercase.
"i like cookies".capitalize(); //"I Like Cookies"
the capitalized string
Trims the leading and trailing spaces off a string.
" i like cookies ".trim() //"i like cookies"
the trimmed string
trims (String.trim) a string AND removes all the double spaces in a string.
the cleaned string
" i like cookies \n\n".clean() //"i like cookies"
Converts an RGB value to hexidecimal. The string must be in the format of “rgb(255,255,255)” or “rgba(255,255,255,1)”;
array | boolean value, defaults to false. Use true if you want the array [‘FF’,’33’,’00’] as output instead of “#FF3300” |
hex string or array. returns “transparent” if the output is set as string and the fourth value of rgba in input string is 0.
"rgb(17,34,51)".rgbToHex(); //"#112233" "rgba(17,34,51,0)".rgbToHex(); //"transparent" "rgb(17,34,51)".rgbToHex(true); //['11','22','33']
Converts a hexidecimal color value to RGB. Input string must be the hex color value (with or without the hash). Also accepts triplets (‘333’);
array | boolean value, defaults to false. Use true if you want the array [255,255,255] as output instead of “rgb(255,255,255)”; |
rgb string or array.
"#112233".hexToRgb(); //"rgb(17,34,51)" "#112233".hexToRgb(true); //[17,34,51]
checks if the passed in string is contained in the String. also accepts an optional second parameter, to check if the string is contained in a list of separated values.
'a b c'.contains('c', ' '); //true 'a bc'.contains('bc'); //true 'a bc'.contains('b', ' '); //false
Returns string with escaped regular expression characters
var search = 'animals.sheeps[1]'.escapeRegExp(); // search is now 'animals\.sheeps\[1\]'
Escaped string
see String.rgbToHex, but as an array method.
same as String.hexToRgb, but as an array method.
Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi