Skip to content

Alex61NN5/easy-read-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⌛ Easy Estimated Read Time

npm version bundlephobia twitter

Simple medium like estimated read times.

Demo 🏄

https://easyreadtime.netlify.com/

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'.

Argument Type Description
string: required string Input String
wordTime: optional number Defaults to 200 - Speed of reading the text in Words per Minute
customString: optional number Default to 'min read' - The text after the duration eg: 2 + 'minute read'

Output

The method returns an object

Property Type Description
duration number Duration of the input string (in minutes)
roundDuration number Duration of the input string (in minutes) rounded to closest minute
totalWords number Number of words in the input string
formattedString string Medium like read time string '2 min read'

Sample Response

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

Support 💬

  • 🐞 For Bug Reports and Enhancements please use the issues section

  • 🕊️ To contact me directly you can find me via my twitter