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