Skip to the content

Capsid menu

src/normalize.ts

18 lines and 3 functions in DrDustinEdwards/capsid, at commit daa875b on 2026-10-24. This file on GitHub.

Functions

The functions of normalize.ts
FunctionLinesComplexityCoveredCRAPMutation
applyDashes10 to 121100%OkCRAP 1No data: mutation testing has not run on this repo yet
normalizeDashes14 to 213100%OkCRAP 3No data: mutation testing has not run on this repo yet
<anonymous:19>19 to 192100%OkCRAP 2No 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");
}