fabric.js/src/util/lang_string.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

if (!String.prototype.trim) {
/**
* 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>
*/
String.prototype.trim = function () {
// 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]+$/, '');
};
}
/**
* Camelizes a string
* @memberOf fabric.util.string
* @method camelize
* @param {String} string String to camelize
* @return {String} Camelized version of a string
*/
function camelize(string) {
return string.replace(/-+(.)?/g, function(match, character) {
return character ? character.toUpperCase() : '';
});
}
/**
* Capitalizes a string
* @memberOf fabric.util.string
* @method capitalize
* @param {String} string String to capitalize
* @return {String} Capitalized version of a string
*/
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
/** @namespace */
fabric.util.string = {
camelize: camelize,
capitalize: capitalize
};