@danieldietrich/reading-time
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

npm versionvulnerabilitiesminzipped size   buildcoverage   Platform   Sponsordonatelicense   Follow

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.

Package Sidebar

Install

npm i @danieldietrich/reading-time

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

7.85 kB

Total Files

6

Last publish

Collaborators

  • danieldietrich