src/normalize.ts
18 lines and 3 functions in DrDustinEdwards/capsid, at commit daa875b on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| applyDashes | 10 to 12 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| normalizeDashes | 14 to 21 | 3 | 100% | OkCRAP 3 | No data: mutation testing has not run on this repo yet |
| <anonymous:19> | 19 to 19 | 2 | 100% | OkCRAP 2 | No data: mutation testing has not run on this repo yet |
Imports
It imports no other module of this repo. Imported by src/doc-statements.ts, src/tools/docs-write.ts.
Source
// Worker-side: the hook only sees Claude Code, not claude.ai or operator writes.
// Prose separators become ", "; titles and markdown headings become " - ".
// Numeric en-dash ranges (2014-2018) become a hyphen.
const EM_OR_BAR = /\s*[—―]\s*/g; // em dash (U+2014), horizontal bar (U+2015)
const EN_RANGE = /(\d)\s*–\s*(\d)/g; // numeric en-dash range -> hyphen
const EN_DASH = /\s*–\s*/g; // remaining en dash used as an em dash
const HEADING = /^\s{0,3}#{1,6}\s/;
function applyDashes(text: string, sep: string): string {
return text.replace(EN_RANGE, "$1-$2").replace(EM_OR_BAR, sep).replace(EN_DASH, sep);
}
export function normalizeDashes(text: string, mode: "prose" | "title" = "prose"): string {
if (!text) return text;
if (mode === "title") return applyDashes(text, " - ");
return text
.split("\n")
.map((line) => applyDashes(line, HEADING.test(line) ? " - " : ", "))
.join("\n");
}