-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapwords.js
More file actions
18 lines (17 loc) · 732 Bytes
/
Copy pathcapwords.js
File metadata and controls
18 lines (17 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function capwords (str) {
// discuss at: http://locutus.io/python/capwords/
// original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// improved by: Waldo Malqui Silva (http://waldo.malqui.info)
// improved by: Robin
// improved by: Kevin van Zonneveld (http://kvz.io)
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// input by: James (http://www.james-bell.co.uk/)
// example 1: capwords('kevin van zonneveld')
// returns 1: 'Kevin Van Zonneveld'
// example 2: capwords('HELLO WORLD')
// returns 2: 'HELLO WORLD'
var pattern = /^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g
return (str + '').replace(pattern, function ($1) {
return $1.toUpperCase()
})
}