reading-duration
v1.1.2
Published
Estimate the reading duration of blog posts and articles. Enhance the user experience by providing readers with an insightful glance at the approximate time required to consume your content.
Downloads
2,901
Maintainers
Readme
Reading Duration 📖⌛
Estimate the reading duration of your blog posts or articles. This lightweight npm package calculates the approximate time it takes for an average reader to consume your content, helping you provide readers with an insightful glance at the commitment required.
Installation 📦
npm install reading-duration
Usage ⚙️
import readingDuration from 'reading-duration';
const text = 'Hello World...';
const readingTime = readingDuration(text);
console.log(readingTime); // => '⌛ 1 min read'
It can also calculate the duration even if your content contains HTML tags(by ignoring them), especially when you're building a blog website with MDX
import readingDuration from 'reading-duration';
const htmlContent = `
<h1>Hello World!</h1>
<p>Here your content...</p>
`;
const readingTime = readingDuration(htmlContent, {
wordsPerMinute: 100
emoji: false
});
console.log(readingTime); // => '1 min read'
API 🎩
readingDuration(content: string, options?: ReadingOptions): string
Parameters
- htmlContent (string): The HTML content of your blog post or article.
- options (optional): An object with the following optional properties:
- wordsPerMinute (number, default: 200): The average words per minute read rate.
- emoji (boolean | string, default: true): Whether to include an emoji in the output.
- Possible emoji values:
- true: '⌛ '
- false: no emoji
- hourglass_done: '⌛ '
- hourglass_not_done: '⏳ '
- stopwatch: '⏱ '
- clock: '🕒 '
- watch: '⌚ '
- timer: '⏲ '
- alarm: '⏰ '
- books: '📚 '
- open_book: '📖 '
- closed_book: '📕 '
- blue_book: '📘 '
- green_book: '📗 '
- orange_book: '📙 '
- notebook: '📓 '
- notebook_alt: '📔 '
- Possible emoji values:
Returns
A string representing the estimated reading time, including an optional emoji.