Skip to content

Instantly share code, notes, and snippets.

@aradnom
Created April 9, 2018 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aradnom/74d53e356cf48e8f9068a1a0af728409 to your computer and use it in GitHub Desktop.
Save aradnom/74d53e356cf48e8f9068a1a0af728409 to your computer and use it in GitHub Desktop.
Simple function for converting a slugified value to display text.
/**
* 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