Created
April 9, 2018 23:06
-
-
Save aradnom/74d53e356cf48e8f9068a1a0af728409 to your computer and use it in GitHub Desktop.
Simple function for converting a slugified value to display text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts passed slug to capitalized display value. Not super clever, just | |
* intended to deal with lowercase, dashed slugs. Ex.: bananas-in-pajamas --> | |
* Bananas In Pajamas | |
* | |
* @param {String} slug Slug to convert to display text | |
* | |
* @return {String} Returns formatted text | |
*/ | |
function slugToDisplay ( slug ) { | |
if ( ! slug ) { return ''; } | |
return slug | |
.split( '-' ) | |
.map( segment => segment.substr( 0, 1 ).toUpperCase() + segment.substr( 1, segment.length ) ) | |
.join( ' ' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment