5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
6
[ ![ Size] [ size-badge ]] [ size ]
7
7
8
- Convert a value to title case using [ AP] [ ] /[ APA] [ ] style.
8
+ Convert a value to [ AP] [ ] /[ APA] [ ] title case.
9
+
10
+ ## Contents
11
+
12
+ * [ What is this?] ( #what-is-this )
13
+ * [ When should I use this?] ( #when-should-i-use-this )
14
+ * [ Install] ( #install )
15
+ * [ Use] ( #use )
16
+ * [ API] ( #api )
17
+ * [ ` apStyleTitleCase(value[, options]) ` ] ( #apstyletitlecasevalue-options )
18
+ * [ Algorithm] ( #algorithm )
19
+ * [ Types] ( #types )
20
+ * [ Compatibility] ( #compatibility )
21
+ * [ Contribute] ( #contribute )
22
+ * [ Security] ( #security )
23
+ * [ License] ( #license )
24
+
25
+ ## What is this?
26
+
27
+ This small package turns a sentence into title case.
28
+
29
+ ## When should I use this?
30
+
31
+ You can use this when you have short text of unknown casing and want to display
32
+ it in a heading or so.
9
33
10
34
## Install
11
35
12
- [ npm] [ ] :
36
+ This package is [ ESM only] [ esm ] .
37
+ In Node.js (version 14.14+, 16.0+), install with [ npm] [ ] :
13
38
14
- ``` bash
39
+ ``` sh
15
40
npm install ap-style-title-case
16
41
```
17
42
43
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
44
+
45
+ ``` js
46
+ import {apStyleTitleCase } from ' https://esm.sh/ap-style-title-case@1'
47
+ ```
48
+
49
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
50
+
51
+ ``` html
52
+ <script type =" module" >
53
+ import {apStyleTitleCase } from ' https://esm.sh/ap-style-title-case@1?bundle'
54
+ </script >
55
+ ```
56
+
18
57
## Use
19
58
20
59
``` js
21
- var titleCase = require ( ' ap-style-title-case' )
60
+ import { apStyleTitleCase } from ' ap-style-title-case'
22
61
23
- console .log (titleCase (' why sunless tanning is A hot trend' ))
62
+ console .log (apStyleTitleCase (' why sunless tanning is A hot trend' ))
24
63
// 'Why Sunless Tanning Is a Hot Trend'
25
64
```
26
65
@@ -30,25 +69,35 @@ console.log(titleCase('why sunless tanning is A hot trend'))
30
69
31
70
Convert a value (` string ` ) to title case (` string ` ) using [ AP] [ ] /[ APA] [ ] style.
32
71
33
- * ` options.keepSpaces ` (` boolean ` , default: ` false ` )
34
- — Superfluous whitespace is ignored by default, turn this on to allow it
35
- * ` options.stopwords ` (` Array.<string> ` , default: see list below)
36
- — Lowercase the given stop words instead of the defaults
72
+ ##### ` options `
73
+
74
+ Configuration (optional).
75
+
76
+ ###### ` options.keepSpaces `
37
77
38
- ## The Rules
78
+ Keep superfluous whitespace (` boolean ` , default: ` false ` ).
79
+ Whitespace is turned into a space by default.
39
80
40
- * Always capitalize the first word, even if it’s a stop word
41
- * Always capitalize the last word, even if it’s a stop word
42
- * Lowercase these words: `a an and at but by for in nor of on or so the to up
43
- yet`
81
+ ###### ` options.stopwords `
44
82
45
- > Many writers make the error of leaving “to be” verbs in lower case.
46
- > Even though “is,” “are,” “was,” and “be,” are all short words, they should
83
+ List of stopwords (` Array<string> ` , default: see below).
84
+ When a lowercased word is included in this list, it will be used as lowercase.
85
+ Otherwise words are capitalized.
86
+
87
+ ## Algorithm
88
+
89
+ * always capitalize the first word, even if it’s a stop word
90
+ * always capitalize the last word, even if it’s a stop word
91
+ * lowercase these words: ` a ` , ` an ` , ` and ` , ` at ` , ` but ` , ` by ` , ` for ` , ` in ` ,
92
+ ` nor ` , ` of ` , ` on ` , ` or ` , ` so ` , ` the ` , ` to ` , ` up ` , ` yet `
93
+
94
+ > Many writers make the error of leaving ` to be ` verbs in lower case.
95
+ > Even though ` is ` , ` are ` , ` was ` , and ` be ` , are all short words, they should
47
96
> still be capitalized in a title because they are verbs.
48
97
>
49
98
> When you write titles that contain prepositions, your word processor will
50
- > likely tell you that you should leave words like “ with,” “ about,” and “around”
51
- > lowercase.
99
+ > likely tell you that you should leave words like ` with ` , ` about ` , and
100
+ > ` around ` lowercase.
52
101
> Defiantly look past the squiggly line indicating a potential error, and
53
102
> remember that in AP title case, prepositions with four or more letters should
54
103
> be capitalized.
@@ -57,12 +106,34 @@ Convert a value (`string`) to title case (`string`) using [AP][]/[APA][] style.
57
106
> AP style does not recommend the use of title case for newspaper headlines, but
58
107
> rather sentence case.
59
108
60
- ## References
109
+ ###### References
110
+
111
+ * [ * How to correctly use AP (and APA) style title case* on
112
+ ` bkacontent.com ` ] ( https://www.bkacontent.com/how-to-correctly-use-apa-style-title-case/ )
113
+ * [ * AP Stylebook* on ` wikipedia.com ` ] ( https://en.wikipedia.org/wiki/AP_Stylebook )
114
+ * [ * APA style* on ` wikipedia.com ` ] ( https://en.wikipedia.org/wiki/APA_style )
115
+ * [ * Title case and sentence case capitalization in APA style* on
116
+ ` apastyle.org ` ] ( http://blog.apastyle.org/apastyle/2012/03/title-case-and-sentence-case-capitalization-in-apa-style.html )
117
+
118
+ ## Types
119
+
120
+ This package is fully typed with [ TypeScript] [ ] .
121
+ It exports the additional type ` Options ` .
122
+
123
+ ## Compatibility
124
+
125
+ This package is at least compatible with all maintained versions of Node.js.
126
+ As of now, that is Node.js 14.14+ and 16.0+.
127
+ It also works in Deno and modern browsers.
61
128
62
- * < https://www.bkacontent.com/how-to-correctly-use-apa-style-title-case/ >
63
- * < https://en.wikipedia.org/wiki/AP_Stylebook >
64
- * < https://en.wikipedia.org/wiki/APA_style >
65
- * < http://blog.apastyle.org/apastyle/2012/03/title-case-and-sentence-case-capitalization-in-apa-style.html >
129
+ ## Contribute
130
+
131
+ Yes please!
132
+ See [ How to Contribute to Open Source] [ contribute ] .
133
+
134
+ ## Security
135
+
136
+ This package is safe.
66
137
67
138
## License
68
139
@@ -88,6 +159,14 @@ Convert a value (`string`) to title case (`string`) using [AP][]/[APA][] style.
88
159
89
160
[ npm ] : https://docs.npmjs.com/cli/install
90
161
162
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
163
+
164
+ [ esmsh ] : https://esm.sh
165
+
166
+ [ typescript ] : https://www.typescriptlang.org
167
+
168
+ [ contribute ] : https://opensource.guide/how-to-contribute/
169
+
91
170
[ license ] : license
92
171
93
172
[ author ] : http://zeke.sikelianos.com
0 commit comments