1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict'
|
11 |
|
12 | const snakecase = require('./snakecase')
|
13 | const lowercase = require('./lowercase')
|
14 | const trimcase = require('./trimcase')
|
15 | const capitalcase = require('./capitalcase')
|
16 |
|
17 | const LOWERCASE_WORDS = 'a,the,and,or,not,but,for,of'.split(',')
|
18 |
|
19 |
|
20 | function titlecase (str) {
|
21 | return snakecase(str).split(/_/g)
|
22 | .map(trimcase)
|
23 | .map(function (word) {
|
24 | var lower = !!~LOWERCASE_WORDS.indexOf(word)
|
25 | if (lower) {
|
26 | return lowercase(word)
|
27 | } else {
|
28 | return capitalcase(word)
|
29 | }
|
30 | }).join(' ')
|
31 | }
|
32 |
|
33 | module.exports = titlecase;
|
34 |
|
35 |
|