Nodejs String Case Convert toCap()

Here you can find the source of toCap()

Method Source Code

'use strict'/*from   w  w  w .ja  v  a 2 s .  co m*/

export default (obj) => String.prototype.toCap.apply(obj)

String.prototype.toCap = function () {
 return this.toUpperCase().charAt(0) + this.slice(1,(this.length));

}

Related

  1. snakeCaseDash()
    String.prototype.snakeCaseDash = function() {
      return this.replace( /([A-Z])/g, function( $1 ) {return "-" + $1.toLowerCase();} );
    };
    
  2. snake_case()
    String.prototype.snake_case = function(){
        return this
            .replace( /[A-Z]/g, function($1) { return '_' + $1 } )
            .toLowerCase();
    
  3. toSnakeCase()
    String.prototype.toSnakeCase = function(){
      return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
    };
    
  4. toCap()
    String.prototype.toCap = function () {
      var result = this.toUpperCase().charAt(0) + this.slice(1, this.length);
      return result;
    };
    
  5. toCap()
    String.prototype.toCap = function() {
      var string = this.toString();
      if(!string.length) return;
      var lastName = string.split(' ').pop();
      var firstName = string.split(' ')[0];
      lastName = lastName[0].toUpperCase() + lastName.slice(1);
      firstName = firstName[0].toUpperCase() + firstName.slice(1);
      string = firstName + " " + lastName;
      return string;
    ...