@danieldietrich/reading-time
v0.0.2
Published
Estimates the reading time of a document
Downloads
17
Maintainers
Readme
reading-time
Estimates the reading time of a document ('1 min read'), similar to DEV.to or Medium.com.
The reading time is calculated by dividing the number of words by a fixed rate, the words per minute. We assume that plain text or markdown are read at 200 words per minute.
It makes sense to change the words per minute option when the document type changes. In the case of html, this way the additional noise of html tags can be compensated without sacrificing the simple word count strategy.
Features:
- Can be applied to plain text, markdown, html etc.
- Estimations can be balanced by providing an average words per minute rate.
- Fast and memory-efficient, does not create intermediate objects other than the return value.
- Simplistic. No default text (like '1 min read'), only numbers.
Currently there is no stream support.
Installation
npm i @danieldietrich/reading-time
Usage
The module supports ES6 import and CommonJS require style.
import readingTime from '@danieldietrich/reading-time';
function example(text) {
const { minutes, words } = readingTime(text);
console.log(`${minutes} min read, ${words} words`);
}
Options
| Option | Description | | -- | -- | | wordBound | Optional predicate that tests if a character is a word bound. Default: space ' ', tab '\t', carriage return '\r' and new line '\n' | | wordsPerMinute | Optional words per minute which an average reader can read. Default: 200 |
Copyright © 2020 by Daniel Dietrich. Released under the MIT license.