Nodejs String Case Convert toCap()

Here you can find the source of toCap()

Method Source Code

//Capitlizes first letter of first name and last name
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;
};

Related

  1. snakeCase()
    String.prototype.snakeCase = function() {
      return this.replace( /([A-Z])/g, function( $1 ) {return "_" + $1.toLowerCase();} );
    };
    
  2. snakeCaseDash()
    String.prototype.snakeCaseDash = function() {
      return this.replace( /([A-Z])/g, function( $1 ) {return "-" + $1.toLowerCase();} );
    };
    
  3. snake_case()
    String.prototype.snake_case = function(){
        return this
            .replace( /[A-Z]/g, function($1) { return '_' + $1 } )
            .toLowerCase();
    
  4. toSnakeCase()
    String.prototype.toSnakeCase = function(){
      return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
    };
    
  5. toCap()
    String.prototype.toCap = function () {
      var result = this.toUpperCase().charAt(0) + this.slice(1, this.length);
      return result;
    };
    
  6. toCap()
    'use strict'
    export default (obj) => String.prototype.toCap.apply(obj)
    String.prototype.toCap = function () {
     return this.toUpperCase().charAt(0) + this.slice(1,(this.length));