An open API service indexing awesome lists of open source software.

https://github.com/lbenie/reading-time-estimator

A medium's like reading time estimator with internationalization support
https://github.com/lbenie/reading-time-estimator

es6 estimator i18n javascript javascript-library medium reading reading-time time typescript typescript-library

Last synced: about 2 months ago
JSON representation

A medium's like reading time estimator with internationalization support

Awesome Lists containing this project

README

          

# reading-time-estimator

[![Test](https://github.com/lbenie/reading-time-estimator/actions/workflows/test.yml/badge.svg)](https://github.com/lbenie/reading-time-estimator/actions/workflows/test.yml)
[![Lint commit messages](https://github.com/lbenie/reading-time-estimator/actions/workflows/commintlint.yml/badge.svg)](https://github.com/lbenie/reading-time-estimator/actions/workflows/commintlint.yml)
[![Release](https://github.com/lbenie/reading-time-estimator/actions/workflows/release.yml/badge.svg)](https://github.com/lbenie/reading-time-estimator/actions/workflows/release.yml)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm](https://img.shields.io/npm/l/reading-time-estimator.svg)](https://github.com/lbenie/reading-time-estimator/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/dt/reading-time-estimator.svg)](https://www.npmjs.com/package/reading-time-estimator)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/reading-time-estimator.svg)](https://www.npmjs.com/package/reading-time-estimator)

[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-)

[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/made-with-typescript.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/uses-badges.svg)](https://forthebadge.com)

A [medium](https://medium.com/)'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](https://medium.com/).

### Installation

With NPM

```bash
npm install reading-time-estimator
```

or Yarn

```bash
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](https://codesandbox.io/s/condescending-rosalind-lll23r?file=/src/App.tsx)

```typescript
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](https://www.npmjs.com/package/reading-time) does not offer
internationalization support which was a must for me.

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/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](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!