Javascript String toCode()

Description

Javascript String toCode()

String.prototype.toCode = function() {
  var code = this
    .toLowerCase()/*from   ww  w  . j av a2  s . com*/
    .replace(/\W/g,' ')
    .replace(/([^ \t]+)/g, function(_, word) {
        return word.capitalize(); }
      )
    .replace(/\W/g,'');


  return code.charAt(0).toLowerCase() + code.slice(1);
};



PreviousNext

Related