21 lines
550 B
TypeScript
21 lines
550 B
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
const FORBIDDEN_WORDS = ["darn", "heck", "gosh"];
|
|
|
|
export function sanitizeText(storyName: string): string {
|
|
const sourcePath = path.join("stories", storyName, "source.txt");
|
|
if (!fs.existsSync(sourcePath)) {
|
|
throw new Error(`Source text not found for story: ${storyName}`);
|
|
}
|
|
|
|
let text = fs.readFileSync(sourcePath, "utf8");
|
|
|
|
FORBIDDEN_WORDS.forEach((word) => {
|
|
const regex = new RegExp(`\\b${word}\\b`, "gi");
|
|
text = text.replace(regex, "***");
|
|
});
|
|
|
|
return text;
|
|
}
|