Nodejs String Title Case titleize(splitter)

Here you can find the source of titleize(splitter)

Method Source Code

String.prototype.titleize = function(splitter) {
  var words = this.split(splitter ? splitter : ' ')
  var array = []/*w  ww . ja v a  2  s . c  o  m*/
  for (var i=0; i<words.length; ++i) {
    array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
  }
  return array.join(' ')
}

Related

  1. titleize()
    String.prototype.titleize = function() {
        return this.substring(0,1).toUpperCase() + this.substring(1);
    
  2. titleize()
    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))
        return array.join(' ')
    
  3. 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(' ');
    ...
    
  4. 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(' ')
    
  5. titleize()
    String.prototype.titleize = function () {
        var str = this.underscore().humanize();
        str = str.replace(/\s\b[\w]/g, function (chr) {
            return chr.toUpperCase();
        });
        return str;
    };
    
  6. toTitleCase
    String.prototype.toTitleCase =
      function() {
        return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
      };
    export default String.prototype.toTitleCase;
    
  7. toTitleCase( selector )
    String.prototype.toTitleCase = function( selector ) {
        var splitArray;
        var finalString = "";
        if ( typeof ( selector ) === 'undefined' ) {
            selector = " ";
            splitArray = this.split ( " " ) ;
        } else {
            splitArray = this.split ( selector ) ;
        splitArray.forEach( function( element ) {
            finalString += element[0].toUpperCase() + element.substr(1) + selector;
        } );
        finalString = finalString.substr( 0, finalString.length-1);
        return finalString;
    
  8. toTitleCase()
    String.prototype.toTitleCase = function(){
      return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
    
  9. toTitleCase()
    String.prototype.toTitleCase = function () {
        return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
    };