Contains String prototypes and Number prototypes.
Valerio Proietti, http://mad4milk.net
MIT-style license.
String.js | Contains String prototypes and Number 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. |
camelCase | Converts a hiphenated string to a camelcase 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. |
Number | contains the internal method toInt. |
Properties | |
toInt | Returns this number; useful because toInt must work on both Strings and Numbers. |
A collection of The String Object prototype methods.
Properties | |
test | Tests a string with a regular expression. |
toInt | parses a string to an integer. |
camelCase | Converts a hiphenated string to a camelcase 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. |
Tests a string with a regular expression.
regex | the regular expression you want to match the string with |
params | optional, any parameters you want to pass to the regex |
an array with the instances of the value searched for or empty array.
"I like cookies".test("cookie"); // returns ["I like cookies", "cookie"]
"I like cookies".test("COOKIE", "i") //ignore case
"I like cookies because cookies are good".test("COOKIE", "ig"); //ignore case, find all instances.
"I like cookies".test("cake"); //returns empty array
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
Converts a hiphenated string to a camelcase string.
"I-like-cookies".camelCase(); //"ILikeCookies"
the camel cased string
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 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]
contains the internal method toInt.
Properties | |
toInt | Returns this number; useful because toInt must work on both Strings and Numbers. |