String.js

Contains String prototypes and Number prototypes.

Dependencies

Moo.js

Author

Valerio Proietti, http://mad4milk.net

License

MIT-style license.

Summary
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.

String

A collection of The String Object prototype methods.

Summary
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.

Properties

test

Tests a string with a regular expression.

Arguments

regex the regular expression you want to match the string with
params optional, any parameters you want to pass to the regex

Returns

an array with the instances of the value searched for or empty array.

Example

"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

toInt

parses a string to an integer.

Returns

either an int or “NaN” if the string is not a number.

Example

var value = "10px".toInt(); // value is 10

camelCase

Converts a hiphenated string to a camelcase string.

Example

"I-like-cookies".camelCase(); //"ILikeCookies"

Returns

the camel cased string

capitalize

Converts the first letter in each word of a string to Uppercase.

Example

"i like cookies".capitalize(); //"I Like Cookies"

Returns

the capitalized string

trim

Trims the leading and trailing spaces off a string.

Example

"    i like cookies     ".trim() //"i like cookies"

Returns

the trimmed string

clean

trims (String.trim) a string AND removes all the double spaces in a string.

Returns

the cleaned string

Example

" i      like     cookies      \n\n".clean() //"i like cookies"

rgbToHex

Converts an RGB value to hexidecimal.  The string must be in the format of “rgb(255, 255, 255)” or “rgba(255, 255, 255, 1)”;

Arguments

array boolean value, defaults to false.  Use true if you want the array [‘FF’, ‘33’, ‘00’] as output instead of #FF3300

Returns

hex string or array. returns transparent if the fourth value of rgba in input string is 0,

Example

"rgb(17,34,51)".rgbToHex(); //"#112233"
"rgba(17,34,51,0)".rgbToHex(); //"transparent"
"rgb(17,34,51)".rgbToHex(true); //[11,22,33]

hexToRgb

Converts a hexidecimal color value to RGB.  Input string must be the hex color value (with or without the hash).  Also accepts triplets (‘333’);

Arguments

array boolean value, defaults to false.  Use true if you want the array [‘255’, ‘255’, ‘255’] as output instead of “rgb(255,255,255)”;

Returns

rgb string or array.

Example

"#112233".hexToRgb(); //"rgb(17,34,51)"
"#112233".hexToRgb(true); //[17,34,51]

Number

contains the internal method toInt.

Summary
Properties
toInt Returns this number; useful because toInt must work on both Strings and Numbers.

Properties

toInt

Returns this number; useful because toInt must work on both Strings and Numbers.

Trims the leading and trailing spaces off a string.
My Object Oriented javascript.