Nodejs String Humanize humanize()

Here you can find the source of humanize()

Method Source Code

String.prototype.humanize = function() {
    var str;/*from ww  w . j a  v  a  2 s  .c om*/
    str = this.replace(/_id$/, "").replace(/_/g, ' ').replace(/([a-z\d]*)/gi, function(match) {
        return match;//.toLowerCase();
    });
    return str.split('.').pop().charAt(0).toLowerCase() + str.split('.').pop().slice(1);
};

Related

  1. humanize()
    String.prototype.humanize=function(){
      return this[0].toUpperCase()+this.replace(/_/g," ").slice(1);
    };
    
  2. humanize()
    String.prototype.humanize = function() {
      var str;
      str = this.replace(/_id$/, "").replace(/_/g, ' ').replace(/([a-z\d]*)/gi, function(match) {
        return match.toLowerCase();
      });
      return str.split('.').pop();
    };
    
  3. humanize()
    String.prototype.humanize = function ()
      var str = this;
      for (var i = 0; i < str.length; i++)
        if (str[i] == str[i].toUpperCase())
          str = str.substr(0, i) +' '+ str[i].toLowerCase() + str.substr(i + 1);
          i++;
    ...
    
  4. humanize()
    String.prototype.humanize = function() {
      var s = this.trim().toLowerCase().replace(/[_]+/g, ' ');
      s = s.replace(/^(.)|\s(.)/g, function($1) {
        return $1.toUpperCase();
      });
      return s;
    
  5. humanize()
    String.prototype.humanize = function(){
      var list = this.strip().split('_')
      first = list[0][0].toUpperCase() + list[0].substr(1,list[0].length)
      list = [first].concat(list.slice(1,list.length))
      return list.join(' ').replace(/\s+/g,' ')
    
  6. humanize()
    String.prototype.humanize = function () {
        return this.capitalize().replace(/_id$/, '').replace(/_/g, ' ');
    };