Created
November 27, 2018 09:49
-
-
Save MohamedLamineAllal/1fcf412c47d65bb7ea9a2b18811e1670 to your computer and use it in GitHub Desktop.
ucwords in javascriopt (uper case Words (only first character un upper and the rest lower of each word)
This file contains hidden or 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
function ucwords(str) { | |
str = str.toLowerCase().replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g, function (replace_latter) { | |
return replace_latter.toUpperCase(); | |
}); //Can use also /\b[a-z]/g | |
return str; //First letter capital in each word | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment