Nodejs String Title Case titleize()

Here you can find the source of titleize()

Method Source Code

// helper to convert not found translations key into titleized string
String.prototype.titleize = function() {
    var words = this.split(' ')
    var array = []
    for (var i=0; i<words.length; ++i) {
        array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
    }//  w  ww . j a  va  2s .co m
    return array.join(' ')
}

Related

  1. titleize()
    String.prototype.titleize = function () {
      return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1);});
    };
    
  2. titleize()
    String.prototype.titleize = function() {
      strings = this.split(' ')
      string  = ''
      for (var i = 0, len = strings.length; i < len; ++i) {
        string += strings[i].charAt(0).toUpperCase() + strings[i].toLowerCase().slice(1)
        if (i != (len-1)) { string += ' ' }
      return string
    function switchPage(page) {
        var links = ['home', 'add', 'import'];
        for (var i=0;i<links.length;i++) {
            var link = document.getElementById(links[i] + '-bar');
            link.className = "";
            if (links[i] == page)
                link.className = "active";
    
  3. titleize()
    String.prototype.titleize = function() {
      return this.charAt(0).toUpperCase() + this.slice(1);
    
  4. titleize()
    String.prototype.titleize = function() {
      words = this.split(' ');
      for(i in words)
        words[i] = words[i].capitalize();
      return words.join(' ');
    
  5. titleize()
    String.prototype.titleize = function() {
        return this.substring(0,1).toUpperCase() + this.substring(1);
    
  6. titleize()
    String.prototype.titleize = function() {
      if(this.length === 0) {
        return '';
      } else {
        var words = this.split(' ');
        for(var i=0, len=words.length; i < len; i++) {
          words[i] = words[i].capitalize();
        return words.join(' ');
    ...
    
  7. titleize()
    String.prototype.titleize = function() {
        var words = this.replace(/_/g, " ").split(' ')
        var array = []
        for (var i=0; i<words.length; ++i) {
            array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
        return array.join(' ')
    
  8. titleize()
    String.prototype.titleize = function () {
        var str = this.underscore().humanize();
        str = str.replace(/\s\b[\w]/g, function (chr) {
            return chr.toUpperCase();
        });
        return str;
    };
    
  9. titleize(splitter)
    String.prototype.titleize = function(splitter) {
      var words = this.split(splitter ? splitter : ' ')
      var array = []
      for (var i=0; i<words.length; ++i) {
        array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
      return array.join(' ')