8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- ** [ hast] [ ] ** utility to estimate the reading time, taking readability of the
12
- document and a target age group into account.
11
+ [ hast] [ ] utility to estimate the reading time, taking readability of the
12
+ document into account.
13
+
14
+ ## Contents
15
+
16
+ * [ What is this?] ( #what-is-this )
17
+ * [ When should I use this?] ( #when-should-i-use-this )
18
+ * [ Install] ( #install )
19
+ * [ Use] ( #use )
20
+ * [ API] ( #api )
21
+ * [ ` readingTime(tree, options?) ` ] ( #readingtimetree-options )
22
+ * [ Types] ( #types )
23
+ * [ Compatibility] ( #compatibility )
24
+ * [ Security] ( #security )
25
+ * [ Related] ( #related )
26
+ * [ Contribute] ( #contribute )
27
+ * [ License] ( #license )
28
+
29
+ ## What is this?
30
+
31
+ This package is a utility that takes a [ hast] [ ] (HTML) syntax tree and estimates
32
+ the reading time, taking readability of the document and a target age group into
33
+ account.
13
34
14
- ## Install
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
+ ## When should I use this?
50
+
51
+ This is a small utility useful when you have an AST, know your audience, and
52
+ want a really smart reading time algorithm.
15
53
16
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
17
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
54
+ The rehype plugin
55
+ [ ` rehype-infer-reading-time-meta ` ] [ rehype-infer-reading-time-meta ]
56
+ wraps this utility to figure, for use with [ ` rehype-meta ` ] [ rehype-meta ] .
18
57
19
- [ npm] [ ] :
58
+ ## Install
59
+
60
+ This package is [ ESM only] [ esm ] .
61
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
20
62
21
63
``` sh
22
64
npm install hast-util-reading-time
23
65
```
24
66
67
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
68
+
69
+ ``` js
70
+ import {readingTime } from " https://esm.sh/hast-util-reading-time@1"
71
+ ```
72
+
73
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
74
+
75
+ ``` html
76
+ <script type =" module" >
77
+ import {readingTime } from " https://esm.sh/hast-util-reading-time@1?bundle"
78
+ </script >
79
+ ```
80
+
25
81
## Use
26
82
27
- Say we have the following HTML from [ “Word per minute: Alphanumeric entry” on
28
- Wikipedia] ( https://en.wikipedia.org/wiki/Words_per_minute#Alphanumeric_entry ) in
29
- ` example.html ` :
83
+ Say our document ` example.html ` contains (from [ “Word per minute: Alphanumeric
84
+ entry” on Wikipedia] [ wiki ] :
30
85
31
86
``` html
32
87
<p >Since the length or duration of words is clearly variable, for the purpose of measurement of text entry, the definition of each "word" is often standardized to be five characters or keystrokes long in English, including spaces and punctuation. For example, under such a method applied to plain English text the phrase "I run" counts as one word, but "rhinoceros" and "let's talk" would both count as two.</p >
@@ -35,51 +90,40 @@ Wikipedia](https://en.wikipedia.org/wiki/Words_per_minute#Alphanumeric_entry) in
35
90
<p >An average professional typist types usually in speeds of 43 to 80 wpm, while some positions can require 80 to 95 (usually the minimum required for dispatch positions and other time-sensitive typing jobs), and some advanced typists work at speeds above 120 wpm. Two-finger typists, sometimes also referred to as "hunt and peck" typists, commonly reach sustained speeds of about 37 wpm for memorized text and 27 wpm when copying text, but in bursts may be able to reach much higher speeds. From the 1920s through the 1970s, typing speed (along with shorthand speed) was an important secretarial qualification and typing contests were popular and often publicized by typewriter companies as promotional tools.</p >
36
91
```
37
92
38
- And our module, ` example.js ` :
93
+ …and our module ` example.js ` looks as follows :
39
94
40
95
``` js
41
- import fs from ' node:fs'
96
+ import fs from ' node:fs/promises '
42
97
import {unified } from ' unified'
43
98
import rehypeParse from ' rehype-parse'
44
99
import {readingTime } from ' hast-util-reading-time'
45
100
46
- const example = fs .readFileSync (' example.html' )
101
+ const example = await fs .readFile (' example.html' )
47
102
const tree = unified ().use (rehypeParse, {fragment: true }).parse (example)
48
103
49
104
console .log (
50
105
` It takes about ${ Math .ceil (readingTime (tree, {age: 18 }))} -${ Math .ceil (readingTime (tree, {age: 14 }))} m to read`
51
106
)
52
107
```
53
108
54
- Now, running ` node example.js ` yields:
109
+ …now running ` node example.js ` yields:
55
110
56
111
``` txt
57
112
It takes about 2-3m to read
58
113
```
59
114
60
115
## API
61
116
62
- This package exports the following identifiers: ` readingTime ` .
117
+ This package exports the identifier ` readingTime ` .
63
118
There is no default export.
64
119
65
120
### ` readingTime(tree, options?) `
66
121
67
- Utility to estimate the reading time, taking readability of the document and
68
- a target age group into account.
122
+ Estimate the reading time.
69
123
70
- The algorithm works as follows:
124
+ ##### ` options `
71
125
72
- * Estimate the WPM of the audience age based on the facts that English can be
73
- read at ±228 WPM (Trauzettel-Klosinski), and that reading rate increases 14
74
- WPM per grade (Carver)
75
- * Apply the readability algorithms [ Dale—Chall] [ dale-chall ] ,
76
- [ Automated Readability] [ automated-readability ] , [ Coleman-Liau] [ ] ,
77
- [ Flesch] [ ] , [ Gunning-Fog] [ ] , [ SMOG] [ ] , and [ Spache] [ ]
78
- * Adjust the WPM of the audience for whether the readability algorithms
79
- estimate its above or below their level
80
- * ` wordCount / adjustedWpm `
81
-
82
- Note: this algorithm is specific to English!
126
+ Configuration (optional).
83
127
84
128
###### ` options.age `
85
129
@@ -90,19 +134,37 @@ expect your readers to all be college graduates, etc.
90
134
91
135
###### Returns
92
136
93
- ` number ` — Reading time in minutes.
94
- The result’s not rounded so it’s possible to retrieve estimated seconds from it.
137
+ Reading time in minutes (` number ` ).
138
+ The result is not rounded so it’s possible to retrieve estimated seconds from
139
+ it.
140
+
141
+ ## Types
142
+
143
+ This package is fully typed with [ TypeScript] [ ] .
144
+ It exports the additional type ` Options ` .
145
+
146
+ ## Compatibility
147
+
148
+ Projects maintained by the unified collective are compatible with all maintained
149
+ versions of Node.js.
150
+ As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
151
+ Our projects sometimes work with older versions, but this is not guaranteed.
95
152
96
153
## Security
97
154
98
155
Use of ` hast-util-reading-time ` is safe.
99
156
100
157
## Related
101
158
159
+ * [ ` rehype-infer-reading-time-meta ` ] [ rehype-infer-reading-time-meta ]
160
+ — infer reading time as file metadata from the document
161
+ * [ ` rehype-meta ` ] [ rehype-meta ]
162
+ — add metadata to the head of a document
163
+
102
164
## Contribute
103
165
104
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
105
- started.
166
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
167
+ ways to get started.
106
168
See [ ` support.md ` ] [ support ] for ways to get help.
107
169
108
170
This project has a [ code of conduct] [ coc ] .
@@ -143,15 +205,23 @@ abide by its terms.
143
205
144
206
[ npm ] : https://docs.npmjs.com/cli/install
145
207
208
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
209
+
210
+ [ esmsh ] : https://esm.sh
211
+
212
+ [ typescript ] : https://www.typescriptlang.org
213
+
146
214
[ license ] : license
147
215
148
216
[ author ] : https://wooorm.com
149
217
150
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
218
+ [ health ] : https://github.com/syntax-tree/.github
151
219
152
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
220
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
153
221
154
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
222
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
223
+
224
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
155
225
156
226
[ hast ] : https://github.com/syntax-tree/hast
157
227
@@ -168,3 +238,9 @@ abide by its terms.
168
238
[ spache ] : https://github.com/words/spache-formula
169
239
170
240
[ smog ] : https://github.com/words/smog-formula
241
+
242
+ [ rehype-infer-reading-time-meta ] : https://github.com/rehypejs/rehype-infer-reading-time-meta
243
+
244
+ [ rehype-meta ] : https://github.com/rehypejs/rehype-meta
245
+
246
+ [ wiki ] : https://en.wikipedia.org/wiki/Words_per_minute#Alphanumeric_entry
0 commit comments