nicco.io/src/lib/readingTime.js

7 lines
256 B
JavaScript

export function readingTimeInMinutes(text, options = {}) {
options = Object.assign({ wpm: 200 }, options)
const cleaned = text.replace(/(<.*?>)|(\\n)|(&#\d*?;)/g, '')
const words = cleaned.split(' ').length
return Math.round(words / options.wpm)
}