https://github.com/untemps/read-per-minute
Class to parse a string and return an estimated reading time based on a lang rate
https://github.com/untemps/read-per-minute
estimated-reading-time lang-rate read-o-meter reading reading-time
Last synced: 3 months ago
JSON representation
Class to parse a string and return an estimated reading time based on a lang rate
- Host: GitHub
- URL: https://github.com/untemps/read-per-minute
- Owner: untemps
- License: mit
- Created: 2021-01-20T19:33:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-17T07:06:53.000Z (about 1 year ago)
- Last Synced: 2024-05-30T16:37:43.131Z (about 1 year ago)
- Topics: estimated-reading-time, lang-rate, read-o-meter, reading, reading-time
- Language: JavaScript
- Homepage:
- Size: 276 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @untemps/read-per-minute
Class to parse a long text and return an estimated reading time based on a lang rate.

[](https://github.com/untemps/read-per-minute/actions)
## Installation
```bash
yarn add @untemps/read-per-minute
```## Usage
Import `ReadPerMinute`:
```javascript
import { ReadPerMinute } from '@untemps/read-per-minute'
```Create an instance of `ReadPerMinute`:
```javascript
const rpm = new ReadPerMinute()
```Call the `parse` method with a string and a lang (see [Override the value for a one-time parsing](#override-the-value-for-a-one-time-parsing) for an alternative usage):
```javascript
rpm.parse('Long text', 'en')
```The `parse` function returns an object with the following properties:
| Property | Description
| -------- | ------------------------------------------------- |
| time | The estimated reading time in minutes |
| words | The number of words in the text |
| rate | The rate value used to calculate the reading time |## Default Rates
Default rate values come from ["How many words do we read per minute? A review and meta-analysis of reading rate"](https://osf.io/4nv9f/) by Marc Brysbaert - Department of Experimental Psychology Ghent University
| Lang | Rate |
| ------- | ---- |
| default | 200 |
| ar | 181 |
| zh | 260 |
| nl | 228 |
| en | 236 |
| fi | 195 |
| fr | 214 |
| de | 260 |
| he | 224 |
| it | 285 |
| ko | 226 |
| es | 278 |
| sv | 218 |If the lang is not listed or is undefined, the default value will be used instead.
## Custom Rates
### Override all the values
You can specify an entire custom rates object in the constructor of an instance:
```javascript
const customRates = {
default: 220,
ar: 191,
zh: 255,
nl: 234,
en: 244,
}
const rpm = new ReadPerMinute(customRates)
```**NOTE**: Set a `default` property in the object if you want the parsing to fallback to a specific value.
Otherwise, the static value will be used (`ReadPerMinute.rates.default`).### Override the value for a one-time parsing
Simply pass the desired custom reading rate in words per minute instead of a language code:
```javascript
// For very fast readers: 425 words per minute.
rpm.parse('Long text', 425)
```**NOTE**: The custom reading rate must be greater than zero or the default value will be used.