read-time-estimator
v1.0.0
Published
A simple, dependency-free utility to estimate reading time of text, Markdown, or HTML content.
Maintainers
Readme
read-time-estimator
A simple, dependency-free utility to estimate reading time of text, Markdown, or HTML content. Perfect for blog posts, news portals, and documentation pages.
Installation
npm install read-time-estimatorFeatures
- 🚀 Zero dependencies — extremely fast and lightweight.
- 🧹 Smart Parsing — automatically strips HTML tags and Markdown formatting to compute an accurate word count.
- ⚙️ Customizable WPM — adjust the Words-Per-Minute reading speed.
- 📦 Simple Output — returns total words, precise decimal read time, and a user-friendly formatted string (e.g.
"3 min read").
Usage
const { estimateReadTime } = require('read-time-estimator');
const blogPost = `
# Welcome to my Awesome Blog!
Today we are going to learn how to build npm packages.
Check out this link: [npm documentation](https://npmjs.com).
Here is some sample code:
\`\`\`javascript
console.log("Hello, World!");
\`\`\`
Hope you found this article helpful!
`;
const result = estimateReadTime(blogPost);
console.log(result);
/* Output:
{
words: 25,
time: 0.125,
timeFormatted: '1 min read'
}
*/Options
estimateReadTime(content, options) accepts the following options:
| Option | Type | Default | Description |
|---|---|---|---|
| wpm | number | 200 | Words per minute used for calculation (typical adult is 200-250 WPM). |
| stripHtml | boolean | true | Strip HTML tags prior to calculating word counts. |
| stripMarkdown | boolean | true | Strip Markdown formatting characters prior to counting. |
// Example with custom speed and HTML stripping disabled
const htmlText = "<p>This is a custom HTML string.</p>";
const result = estimateReadTime(htmlText, {
wpm: 100, // slower reading speed
stripHtml: false
});License
MIT
