Last active
August 14, 2019 21:37
-
-
Save marcelo-ribeiro/1316ee336d93af721b348e8efb8cc278 to your computer and use it in GitHub Desktop.
Javascript String Capitalize
This file contains 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
export const capitalize = value => { | |
if (!value) return ""; | |
const list = value.toString().trim().split(" "); | |
list.forEach((item, index) => { | |
list[index] = item[0].toUpperCase() + item.slice(1).toLowerCase(); | |
}); | |
return list.join(" "); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment