// Names withheld at a victim's request (names-withheld.json). Used by every export. import { readFileSync } from "fs"; const WITHHELD: Record = JSON.parse( readFileSync(new URL("names-withheld.json", import.meta.url), "utf8"), ); // columns that point at sources; sources may name the victim const LEFT_ALONE = /^(source_\d+|url_\d+|other_source_urls|dossier_file|id|case_id)$/; export const withhold = (id: number | string, column: string, value: string): string => { const rule = WITHHELD[String(id)]; if (!rule || LEFT_ALONE.test(column)) return value; if (column === "victim" || column === "title") return rule.victim_title; let text = value; for (const [from, to] of rule.replace) text = text.split(from).join(to); // a replacement that now opens a sentence or a summary section return text.replace(/(^|[.!?]\s+|\*\*\s+)the victim/g, (_, before) => `${before}The victim`); }; // every field quoted: a spreadsheet import that also splits on semicolons or tabs cannot break a cell export const csvCell = (value: unknown): string => '"' + (value == null ? "" : String(value)).replace(/\s*[\r\n]+\s*/g, " ").replace(/"/g, '""') + '"';