@@ -18,7 +18,8 @@ document into account.
18
18
* [ Install] ( #install )
19
19
* [ Use] ( #use )
20
20
* [ API] ( #api )
21
- * [ ` readingTime(tree, options?) ` ] ( #readingtimetree-options )
21
+ * [ ` readingTime(tree[, options]) ` ] ( #readingtimetree-options )
22
+ * [ ` Options ` ] ( #options )
22
23
* [ Types] ( #types )
23
24
* [ Compatibility] ( #compatibility )
24
25
* [ Security] ( #security )
@@ -32,20 +33,6 @@ This package is a utility that takes a [hast][] (HTML) syntax tree and estimates
32
33
the reading time, taking readability of the document and a target age group into
33
34
account.
34
35
35
- The algorithm works as follows:
36
-
37
- * estimate the WPM (words per minute) of the audience age based on the facts
38
- that English can be read at ±228 WPM (Trauzettel-Klosinski), and that
39
- reading rate increases 14 WPM per grade (Carver)
40
- * apply the readability algorithms [ Dale—Chall] [ dale-chall ] ,
41
- [ Automated Readability] [ automated-readability ] , [ Coleman-Liau] [ ] ,
42
- [ Flesch] [ ] , [ Gunning-Fog] [ ] , [ SMOG] [ ] , and [ Spache] [ ]
43
- * adjust the WPM of the audience for whether the readability algorithms
44
- estimate its above or below their level
45
- * ` wordCount / adjustedWpm = readingTime `
46
-
47
- > ⚠️ ** Important** : this algorithm is specific to English.
48
-
49
36
## When should I use this?
50
37
51
38
This is a small utility useful when you have an AST, know your audience, and
@@ -58,7 +45,7 @@ wraps this utility to figure, for use with [`rehype-meta`][rehype-meta].
58
45
## Install
59
46
60
47
This package is [ ESM only] [ esm ] .
61
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
48
+ In Node.js (version 14.14+ and or 16.0+), install with [ npm] [ ] :
62
49
63
50
``` sh
64
51
npm install hast-util-reading-time
@@ -67,7 +54,7 @@ npm install hast-util-reading-time
67
54
In Deno with [ ` esm.sh ` ] [ esmsh ] :
68
55
69
56
``` js
70
- import {readingTime } from " https://esm.sh/hast-util-reading-time@1"
57
+ import {readingTime } from ' https://esm.sh/hast-util-reading-time@1'
71
58
```
72
59
73
60
In browsers with [ ` esm.sh ` ] [ esmsh ] :
@@ -112,40 +99,71 @@ It takes about 2-3m to read
112
99
113
100
## API
114
101
115
- This package exports the identifier ` readingTime ` .
102
+ This package exports the identifier [ ` readingTime ` ] [ readingtime ] .
116
103
There is no default export.
117
104
118
- ### ` readingTime(tree, options? ) `
105
+ ### ` readingTime(tree[ , options] ) `
119
106
120
- Estimate the reading time.
107
+ Estimate the reading time, taking readability of the document and a target age
108
+ group into account.
121
109
122
- ##### ` options `
110
+ For some more background info/history and a few insight on where this all comes
111
+ from, see [ How estimated reading times increase content engagement] [ martech ] .
123
112
124
- Configuration (optional).
113
+ ###### Algorithm
125
114
126
- ###### ` options.age `
115
+ The algorithm works as follows:
127
116
128
- Target age group (` number ` , default: ` 16 ` ).
129
- This is the age your target audience was still in school.
130
- Set it to 18 if you expect all readers to have finished high school, 21 if you
131
- expect your readers to all be college graduates, etc.
117
+ * estimate the WPM (words per minute) of the audience age based on the facts
118
+ that English can be read at ±228 WPM (Trauzettel-Klosinski), and that
119
+ reading rate increases 14 WPM per grade (Carver)
120
+ * apply the readability algorithms [ Dale—Chall] [ dale-chall ] ,
121
+ [ Automated Readability] [ automated-readability ] , [ Coleman-Liau] [ ] ,
122
+ [ Flesch] [ ] , [ Gunning-Fog] [ ] , [ SMOG] [ ] , and [ Spache] [ ]
123
+ * adjust the WPM of the audience for whether the readability algorithms
124
+ estimate its above or below their level
125
+ * ` wordCount / adjustedWpm = readingTime `
126
+
127
+ > ⚠️ ** Important** : this algorithm is specific to English.
128
+
129
+ ###### Parameters
130
+
131
+ * ` tree ` ([ ` Node ` ] [ node ] )
132
+ — tree to inspect
133
+ * ` options ` ([ ` Options ` ] [ options ] )
134
+ — configuration
132
135
133
136
###### Returns
134
137
135
- Reading time in minutes (` number ` ).
138
+ Estimated reading time in minutes (` number ` ).
139
+
136
140
The result is not rounded so it’s possible to retrieve estimated seconds from
137
141
it.
138
142
143
+ ### ` Options `
144
+
145
+ Configuration (TypeScript type).
146
+
147
+ ##### Fields
148
+
149
+ ###### ` age `
150
+
151
+ Target age group (` number ` , default: ` 16 ` ).
152
+
153
+ This is the age your target audience was still in school.
154
+ Set it to 18 if you expect all readers to have finished high school, 21 if you
155
+ expect your readers to all be college graduates, etc.
156
+
139
157
## Types
140
158
141
159
This package is fully typed with [ TypeScript] [ ] .
142
- It exports the additional type ` Options ` .
160
+ It exports the additional type [ ` Options ` ] [ options ] .
143
161
144
162
## Compatibility
145
163
146
164
Projects maintained by the unified collective are compatible with all maintained
147
165
versions of Node.js.
148
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
166
+ As of now, that is Node.js 14.14+ and 16 .0+.
149
167
Our projects sometimes work with older versions, but this is not guaranteed.
150
168
151
169
## Security
@@ -223,6 +241,8 @@ abide by its terms.
223
241
224
242
[ hast ] : https://github.com/syntax-tree/hast
225
243
244
+ [ node ] : https://github.com/syntax-tree/hast#nodes
245
+
226
246
[ dale-chall ] : https://github.com/words/dale-chall-formula
227
247
228
248
[ automated-readability ] : https://github.com/words/automated-readability
@@ -242,3 +262,9 @@ abide by its terms.
242
262
[ rehype-meta ] : https://github.com/rehypejs/rehype-meta
243
263
244
264
[ wiki ] : https://en.wikipedia.org/wiki/Words_per_minute#Alphanumeric_entry
265
+
266
+ [ martech ] : https://martech.org/estimated-reading-times-increase-engagement/
267
+
268
+ [ readingtime ] : #readingtimetree-options
269
+
270
+ [ options ] : #options
0 commit comments