6 description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
8 license: MIT-style license.
19 test: function(regex, params){
20 return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
23 contains: function(string, separator){
24 return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
28 return this.replace(/^\s+|\s+$/g, '');
32 return this.replace(/\s+/g, ' ').trim();
35 camelCase: function(){
36 return this.replace(/-\D/g, function(match){
37 return match.charAt(1).toUpperCase();
41 hyphenate: function(){
42 return this.replace(/[A-Z]/g, function(match){
43 return ('-' + match.charAt(0).toLowerCase());
47 capitalize: function(){
48 return this.replace(/\b[a-z]/g, function(match){
49 return match.toUpperCase();
53 escapeRegExp: function(){
54 return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
57 toInt: function(base){
58 return parseInt(this, base || 10);
62 return parseFloat(this);
65 hexToRgb: function(array){
66 var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
67 return (hex) ? hex.slice(1).hexToRgb(array) : null;
70 rgbToHex: function(array){
71 var rgb = this.match(/\d{1,3}/g);
72 return (rgb) ? rgb.rgbToHex(array) : null;
75 substitute: function(object, regexp){
76 return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
77 if (match.charAt(0) == '\\') return match.slice(1);
78 return (object[name] != null) ? object[name] : '';