Skip to content

Instantly share code, notes, and snippets.

@lacymorrow
Created August 9, 2023 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacymorrow/b60fbbde039f502a2577460ba171d52b to your computer and use it in GitHub Desktop.
Save lacymorrow/b60fbbde039f502a2577460ba171d52b to your computer and use it in GitHub Desktop.
JS function to format a camelCase string into a "Camel Case" pretty string
function prettyFormat(str) {
return str.split(/(?=[A-Z])/)
.map(function(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
})
.join(' ');
}
@lacymorrow
Copy link
Author

lacymorrow commented Aug 9, 2023

Usage

let camelCaseStr = "thisIsAStringInCamelCase";
let prettyStr = prettyFormat(camelCaseStr);
console.log(prettyStr); // "This Is A String In Camel Case"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment