Skip to content

Instantly share code, notes, and snippets.

View rodrigojusto's full-sized avatar

Rodrigo Souza Justo rodrigojusto

View GitHub Profile
@rodrigojusto
rodrigojusto / ucwords.js
Created October 18, 2017 20:30 — forked from rickycheers/ucwords.js
ucwords in JavaScript - Equivalent to PHP's ucwords() Returns a string with the first letter in upper case of each word.
String.prototype.ucwords = function() {
str = this.toLowerCase();
return str.replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,
function(s){
return s.toUpperCase();
});
};