1.0.6 • Published 5 years ago

easy-read-time v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

⌛ Easy Estimated Read Time

npm version bundlephobia npm downloads twitter

Simple estimated medium like read times.

Features 🔥

  • Less than 4kb! (1.08kb Minified)
  • Zero dependencies!
  • Calculates read time of input string (rounds to closest minute).
  • Pass in plain text / HTML / markdown.
  • Strips all markdown and HTML for better read time estimates.
  • Easy to use! 💪

Install 🔮

$ npm i easy-read-time

or

$ yarn add easy-read-time

Usage 💻

import getReadTime from "easy-read-time";

getReadTime(text, 200);

Input

The function takes three arguments the string you wish to get the read time for, the speed of reading the text in words per minute, the default is set to 200 (the average reading time for adults is 250 - 300 words per minute) allowing extra time for viewing of images and other content, and a custom string this field is optional and the default is 'min read', if you pass in 'minute read' formattedString will return '2 minute read'.

ArgumentTypeDescription
string: requiredstringInput String
wordTime: optionalnumberDefaults to 200 - Speed of reading the text in Words per Minute
customString: optionalnumberDefault to 'min read' - The text after the duration eg: 2 + 'minute read'

Output

The method returns an object

PropertyTypeDescription
durationnumberDuration of the input string (in minutes)
roundDurationnumberDuration of the input string (in minutes) rounded to closest minute
totalWordsnumberNumber of words in the input string
formattedStringstringMedium like read time string '2 min read'

Sample Response

{
    duration: 2.3,
    roundDuration: 2,
    totalWords: 400,
    formattedString: '2 min read'
}