Skip to content

Instantly share code, notes, and snippets.

@r4881t
Created June 10, 2023 20:22
Show Gist options
  • Save r4881t/1f1af03b70ef7604be4d5501658cf236 to your computer and use it in GitHub Desktop.
Save r4881t/1f1af03b70ef7604be4d5501658cf236 to your computer and use it in GitHub Desktop.
Get category & sub category names to show in UI
function getPresentableCatText(slug: string): string {
const words = slug.split('-');
const capitalizedWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
return capitalizedWords.join(' ');
}
/*
const slugifiedString = 'arts-and-entertainment';
const unslugifiedString = getPresentableCatText(slugifiedString);
console.log(unslugifiedString);
Arts And Entertainment
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment