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
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| countWords | 12 to 14 | 1 | 33% | OkCRAP 1.3 | No data: no mutants in this code |
| minutesForWords | 20 to 22 | 1 | 0% | OkCRAP 2 | No data: no mutants in this code |
| readingTimeMinutes | 28 to 30 | 1 | 33% | OkCRAP 1.3 | No 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));
}