Skip to content

Instantly share code, notes, and snippets.

@MohamedLamineAllal
Created November 27, 2018 09:49
Show Gist options
  • Save MohamedLamineAllal/1fcf412c47d65bb7ea9a2b18811e1670 to your computer and use it in GitHub Desktop.
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)
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