@lookworld4/read-time-estimate
v1.0.0
Published
Tiny helpers to estimate blog-style read time (e.g. "5 min read") from plain or HTML text.
Maintainers
Readme
read-time-estimate
Small helpers to compute blog-style read times (for example 5 min read) so readers know what they are committing to before long posts.
Install
npm install @lookworld4/read-time-estimateUsage
import {
readTimeEstimate,
estimateReadTime,
formatReadTimeLabel,
DEFAULT_WORDS_PER_MINUTE,
} from '@lookworld4/read-time-estimate';
const article = 'word '.repeat(400); // ~400 words
readTimeEstimate(article);
// { wordCount: 400, minutes: 2, label: '2 min read' }
estimateReadTime(article, { wordsPerMinute: 250 });
// { wordCount: 400, minutes: 2 }
formatReadTimeLabel(7);
// '7 min read'
// Rough HTML body: strip tags before counting
readTimeEstimate('<p>Hello <strong>world</strong></p>', { stripHtml: true });
// { wordCount: 2, minutes: 1, label: '1 min read' }API
| Export | Role |
|--------|------|
| readTimeEstimate(text, options?) | Returns { wordCount, minutes, label }. |
| estimateReadTime(text, options?) | Returns { wordCount, minutes } only. |
| formatReadTimeLabel(minutes) | Turns a minute count into N min read. |
| DEFAULT_WORDS_PER_MINUTE | 200 — override via wordsPerMinute. |
Options
wordsPerMinute— defaults to200.minMinutes— defaults to1(empty or very short text still gets at least one minute in the label).stripHtml— whentrue, removes tags with a simple regex before counting; fine for CMS HTML, not a full sanitizer.
License
MIT
