UNPKG

hast-util-reading-time

Version:
48 lines (47 loc) 1.74 kB
/** * Estimate the reading time, taking readability of the document and a target * age group into account. * * For some more background info/history and a few insight on where this all * comes from, see: <https://martech.org/estimated-reading-times-increase-engagement/>. * * ###### Algorithm * * The algorithm works as follows: * * * estimate the WPM (words per minute) of the audience age based on the facts * that English can be read at ±228 WPM (Trauzettel-Klosinski), and that * reading rate increases 14 WPM per grade (Carver) * * apply the readability algorithms Dale—Chall, Automated Readability, * Coleman-Liau, Flesch, Gunning-Fog, SMOG, and Spache * * adjust the WPM of the audience for whether the readability algorithms * estimate its above or below their level * * `wordCount / adjustedWpm = readingTime` * * > ⚠️ **Important**: this algorithm is specific to English. * * @param {Nodes} tree * Tree to inspect. * @param {Readonly<Options> | null | undefined} [options] * Configuration (optional). * @returns {number} * Estimated reading time in minutes. * * The result is not rounded so it’s possible to retrieve estimated seconds * from it. */ export function readingTime(tree: Nodes, options?: Readonly<Options> | null | undefined): number; export type Nodes = import('hast').Nodes; /** * Configuration */ export type Options = { /** * Target age group (default: `16`). * * This is the age your target audience was still in school. * Set it to 18 if you expect all readers to have finished high school, * 21 if you expect your readers to all be college graduates, etc. */ age?: number | null | undefined; };