1 if (!String.prototype.trim) {
  2   /**
  3    * Trims a string (removing whitespace from the beginning and the end)
  4    * @method trim
  5    * @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim">String#trim on MDN</a>
  6    */
  7   String.prototype.trim = function () {
  8     // this trim is not fully ES3 or ES5 compliant, but it should cover most cases for now
  9     return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '');
 10   };
 11 }
 12 
 13 /**
 14  * Camelizes a string
 15  * @memberOf fabric.util.string
 16  * @method camelize
 17  * @param {String} string String to camelize
 18  * @return {String} Camelized version of a string
 19  */
 20 function camelize(string) {
 21   return string.replace(/-+(.)?/g, function(match, character) {
 22     return character ? character.toUpperCase() : '';
 23   });
 24 }
 25 
 26 /**
 27  * Capitalizes a string
 28  * @memberOf fabric.util.string
 29  * @method capitalize
 30  * @param {String} string String to capitalize
 31  * @return {String} Capitalized version of a string
 32  */
 33 function capitalize(string) {
 34   return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
 35 }
 36 
 37 /** @namespace */
 38 fabric.util.string = {
 39   camelize: camelize,
 40   capitalize: capitalize
 41 };