Skip to content

Instantly share code, notes, and snippets.

@feload
Last active October 30, 2017 16:19
Show Gist options
  • Save feload/92e2fc393273d453f4a07a3a9c4b3058 to your computer and use it in GitHub Desktop.
Save feload/92e2fc393273d453f4a07a3a9c4b3058 to your computer and use it in GitHub Desktop.
Formats a string into a paragraph string.
export const p = (str = "") => {
if(!str || str.length < 1) return "";
str = str.replace('_', ' ');
return str.split(" ").map((word, index) => {
if(index == 0) {
const wordChunks = word.toLocaleLowerCase().split('');
wordChunks[0] = wordChunks[0].toUpperCase();
return wordChunks.join('');
}else{
return word.toLowerCase();
}
}).join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment