Nodejs String Title Case titleCase()

Here you can find the source of titleCase()

Method Source Code

/** Make title case version of string.
    @returns original string with the first character capitalised.
 **///from  w  ww .j a  v a2  s .co  m
String.prototype.titleCase= function()
{
    return this.charAt(0).toUpperCase() + this.substr(1);
}

Related

  1. cleanTitle()
    String.prototype.cleanTitle = function() {
      var title = this.trim().replaceHtmlEntites();
      title = encodeURI(title);
      return title.replace(/&/g, '%26').replace(/#/g, '%23');
    };
    
  2. title()
    String.prototype.title = function() {
        return this.replace(/\w\S*/g, function(txt) {
            return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
        });
    };
    
  3. title()
    String.prototype.title = function() {
      return this.charAt(0).toUpperCase() + this.slice(1);
    };
    module.exports = String;
    
  4. titleCase()
    String.prototype.titleCase = function () {  
      return this.replace(/\w\S*/g, (txt) => {
        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
      });
    };
    
  5. titleCase(str)
    function titleCase(str) {
      var arr = str.split(" ");
      var combineArr = [];
      var resultArr = [];
      for(var i = 0; i<arr.length; i++){
        var upperArr = [];
        var lowerArr = [];  
        for(var j = 0; j < arr[i].length; j++){      
          if(j === 0){
    ...
    
  6. titleCase(str)
    function titleCase(str) {
      var arr = str.split(" ");
      var first;
      var ends = [];
      var temp;
      var arrFixed = [];
      for (i = 0; i < arr.length; i++){
        first = [];
        ends = [];
    ...
    
  7. titleCase(str)
    function titleCase(str) {
      var splitted = str.toLowerCase().split(' ');
      for (var i = 0; i < splitted.length; i++) {
        var holder = splitted[i];    
        var bigLetter = holder.charAt(0).toUpperCase();
        holder = holder.slice(1, holder.length);
        splitted[i] = bigLetter.concat(holder);
      str = splitted.join(' ');
    ...
    
  8. titleCase(string)
    function titleCase(str) {
        var newTitle = str.split(' ');
        var updateTitle = [];
        for (var st in newTitle) {
            updateTitle[st] = newTitle[st]
                .toLowerCase()
                .replaceAt(0, newTitle[st].charAt(0).toUpperCase());
        return updateTitle.join(' ');
    ...