Skip to content

Commit

Permalink
Update string-prototypes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
christianjames committed Aug 13, 2015
1 parent 156a635 commit f21063e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions string-prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ String.prototype.isEmail = function () {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ucwords = function () {
// example 1: ucwords('kevin van zonneveld');
// returns 1: 'Kevin Van Zonneveld'
// example 2: ucwords('HELLO WORLD');
// returns 2: 'HELLO WORLD'

var str = this;
return this.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function($1) {
return $1.toUpperCase();
});

}

0 comments on commit f21063e

Please sign in to comment.