npm.io
2.6.0 • Published 2 months ago

reading-time-estimator

Licence
MIT
Version
2.6.0
Deps
2
Size
592 kB
Vulns
2
Weekly
0
Stars
61

reading-time-estimator

Test Lint commit messages Release Commitizen friendly semantic-release npm npm npm bundle size (minified)

All Contributors

forthebadge forthebadge forthebadge

A medium's like reading time estimator with internationalization support.

Documentation

Reading Time Estimator was created to provide an estimate of how long to read an article or blog as seen on medium.

Installation

With NPM

  npm install reading-time-estimator

or Yarn

  yarn add reading-time-estimator
API

The API is fairly simple. readingTime accepts the text to analyze plus an optional options object.

Per default the locale is set to english en.

Per default the words per minute is set to 200.

Inputs are parsed as Markdown and sanitized as HTML automatically before word counting.

You can also provide translations to override locale strings or htmlSanitizerOptions to customize how markup is handled.

At the moment it supports these locales: 'en', 'fr', 'es', 'zh-cn', 'zh-tw', 'ja', 'de', 'pt-br', 'tr', 'ro', 'bn', 'sk', 'cs', 'ru', 'vi', 'it', 'id' and 'hi'

Usage

Try it live here

import { readingTime } from 'reading-time-estimator'

const text = 'some text to parse'

// custom words per minute
const result = readingTime(text, { wordsPerMinute: 10 })

// output:
// {
//   minutes: 4,
//   words: 43,
//   text: `4 min read`
// }

// with french locale
import { fr } from 'reading-time-estimator/i18n/fr'

const frenchResult = readingTime(text, {
  wordsPerMinute: 10,
  language: 'fr',
  {
    fr,
  },
})

// output:
// {
//   minutes: 4,
//   words: 43,
//   text: `4 min de lecture`
// }

Why Not ...?

reading-time

This package does not offer internationalization support which was a must for me.

Contributors

Thanks goes to these wonderful people (emoji key):

Lucien Bénié
Lucien Bénié

Victor Sierra
Victor Sierra

ZhangC
ZhangC

Rich11
Rich11

Matheus Oliveira
Matheus Oliveira

Can Güven
Can Güven

Alexander Strutz
Alexander Strutz

凝结尾迹
凝结尾迹

Muhammad Faisal Amin
Muhammad Faisal Amin

Oliver Groma
Oliver Groma

Luo Wenjie
Luo Wenjie

CK Wong
CK Wong

Shubhankar Valimbe
Shubhankar Valimbe

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords