JSFiddle - React, Tailwind, and code Playground

by WhetDawg

JavaScript

function __toProperCase() {
    return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
}

String.prototype.toProperCase = __toProperCase;

function __toProperCaseSuffix(rawSuffix) {
    var suffix = rawSuffix.replace(/[.]/g,'');    // remove periods
    
    if( suffix == 'jr' ) {
        suffix = 'Jr.';
    } else if( suffix == 'sr' ) {
        suffix = 'Sr.';
    } else if( suffix == 'md' ) {
        suffix = 'M.D.';
    } else if( suffix == 'phd') {
        suffix = 'Ph.D.';
    } else if( suffix == 'od' ) {
        suffix = 'O.D.'; 
    } else if(suffix == 'pharmd' ) {
        suffix = 'Pharm.D.';        
    } else if(suffix == 'incorporated' ) {
        suffix = 'Incorporated';
    } else if(suffix == 'inc' ) {
        suffix = 'Inc.';
    } else {
        suffix = rawSuffix.toUpperCase();
    }
    
    return suffix;
}

function __toDisplayName() {
    var i,j,aNames,aSuffixes,suffix,nComma, commaFound;
    var displayName;
        
    var rawName = this;
    
    // remove leading / trailing whitespace then remove excess whitespace
     
    rawName = rawName.toLowerCase(); 
    
    nComma = rawName.search(',') 
    commaFound = (nComma == -1 ? false : true);
    
    if( !commaFound ) {                   
        aNames = rawName.replace(/^\s+|\s+$/g,'').replace( /[\s\n\r]+/g, ' ' ).split(' ');
    }
    else {                                
        aNames = rawName.substring(0,nComma).replace(/^\s+|\s+$/g,'').replace( /[\s\n\r]+/g, ' ' ).split(' ');
        
        aSuffixes = rawName.substring(nComma+1).replace(/,/g,' ').replace(/^\s+|\s+$/g,'').replace( /[\s\n\r]+/g, ' ' ).split(' ');
                
        for( j=0; j < aSuffixes.length; j++) {
            aSuffixes[j] = __toProperCaseSuffix(aSuffixes[j]);
        }
    }  

    displayName = '';
    
    for( j=0; j < aNames.length; j++ ) {
        displayName += (j > 0 ? ' ':'') + aNames[j].toProperCase();
    }

    if( commaFound ) {
        for( j=0; j < aSuffixes.length; j++...