Created
December 5, 2013 06:14
-
-
Save duan-li/7800878 to your computer and use it in GitHub Desktop.
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
function ucwords (str) { | |
// http://kevin.vanzonneveld.net | |
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) | |
// + improved by: Waldo Malqui Silva | |
// + bugfixed by: Onno Marsman | |
// + improved by: Robin | |
// + input by: James (http://www.james-bell.co.uk/) | |
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
// * example 1: ucwords('kevin van zonneveld'); | |
// * returns 1: 'Kevin Van Zonneveld' | |
// * example 2: ucwords('HELLO WORLD'); | |
// * returns 2: 'HELLO WORLD' | |
return (str + '').replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function ($1) { | |
return $1.toUpperCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment