Skip to the content

Capsid menu

app/lib/content/reading-time.mjs

26 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.

Functions

The functions of reading-time.mjs
FunctionLinesComplexityCoveredCRAPMutation
countWords12 to 14133%OkCRAP 1.3No data: no mutants in this code
minutesForWords20 to 2210%OkCRAP 2No data: no mutants in this code
readingTimeMinutes28 to 30133%OkCRAP 1.3No data: no mutants in this code

Imports

It imports no other module of this repo. Imported by app/lib/blog-view.ts, app/lib/content/pipeline.mjs.

Source

// Imports nothing: the editor's chunk runs in the browser, and pipeline.mjs would bring shiki with it.

// Changing this restates every published post's reading time on the next regeneration.
const WORDS_PER_MINUTE = 200;

/**
 * Counts markdown syntax as words on purpose: it is the count published reading times were built with.
 *
 * @param {string} markdownText
 * @returns {number}
 */
export function countWords(markdownText) {
  return markdownText.trim().split(/\s+/).filter(Boolean).length;
}

/**
 * @param {number} words
 * @returns {number}
 */
function minutesForWords(words) {
  return Math.max(1, Math.round(words / WORDS_PER_MINUTE));
}

/**
 * @param {string} markdownText
 * @returns {number}
 */
export function readingTimeMinutes(markdownText) {
  return minutesForWords(countWords(markdownText));
}