2010-06-17 14:00:47 +00:00
|
|
|
if (!String.prototype.trim) {
|
2010-10-15 02:16:24 +00:00
|
|
|
/**
|
|
|
|
|
* Trims a string (removing whitespace from the beginning and the end)
|
|
|
|
|
* @method trim
|
2010-10-19 20:27:24 +00:00
|
|
|
* @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim">String#trim on MDN</a>
|
2010-10-15 02:16:24 +00:00
|
|
|
*/
|
2010-06-17 14:00:47 +00:00
|
|
|
String.prototype.trim = function () {
|
2010-09-14 22:57:55 +00:00
|
|
|
// this trim is not fully ES3 or ES5 compliant, but it should cover most cases for now
|
|
|
|
|
return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '');
|
2010-06-17 14:00:47 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 02:16:24 +00:00
|
|
|
/**
|
|
|
|
|
* Camelizes a string
|
|
|
|
|
* @memberOf fabric.util.string
|
|
|
|
|
* @method camelize
|
|
|
|
|
* @param {String} string String to camelize
|
|
|
|
|
* @return {String} Camelized version of a string
|
|
|
|
|
*/
|
2010-06-17 14:00:47 +00:00
|
|
|
function camelize(string) {
|
|
|
|
|
return string.replace(/-+(.)?/g, function(match, character) {
|
|
|
|
|
return character ? character.toUpperCase() : '';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 02:16:24 +00:00
|
|
|
/**
|
|
|
|
|
* Capitalizes a string
|
|
|
|
|
* @memberOf fabric.util.string
|
|
|
|
|
* @method capitalize
|
|
|
|
|
* @param {String} string String to capitalize
|
|
|
|
|
* @return {String} Capitalized version of a string
|
|
|
|
|
*/
|
2010-06-17 14:00:47 +00:00
|
|
|
function capitalize(string) {
|
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 02:16:24 +00:00
|
|
|
/** @namespace */
|
2010-07-10 01:50:13 +00:00
|
|
|
fabric.util.string = {
|
2010-06-17 14:00:47 +00:00
|
|
|
camelize: camelize,
|
|
|
|
|
capitalize: capitalize
|
|
|
|
|
};
|