diff --git a/src/util.js b/src/util.js index 068a8a1..58781b3 100644 --- a/src/util.js +++ b/src/util.js @@ -1,12 +1,13 @@ import animals from "./utils/animals.json"; import moment from "moment"; import { + DataSet, + pattern, RegExpMatcher, TextCensor, - asteriskCensorStrategy, englishDataset, englishRecommendedTransformers, - keepStartCensorStrategy, + fixedPhraseCensorStrategy, } from "obscenity"; import red from "@material-ui/core/colors/red"; import pink from "@material-ui/core/colors/pink"; @@ -24,13 +25,24 @@ import amber from "@material-ui/core/colors/amber"; import orange from "@material-ui/core/colors/orange"; import deepOrange from "@material-ui/core/colors/deepOrange"; +const fixedDataset = englishDataset + .removePhrasesIf((phrase) => phrase.metadata.originalWord === "dick") + .addPhrase((phrase) => + phrase + .setMetadata({ originalWord: "dick" }) + .addPattern(pattern`dick`) + .addPattern(pattern`|dck|`) + .addWhitelistedTerm("benedick") + .addWhitelistedTerm("dickens") + ) + .addPhrase((phrase) => + phrase.setMetadata({ originalWord: "fuck" }).addWhitelistedTerm("fickle") + ); export const badWords = new RegExpMatcher({ - ...englishDataset.build(), + ...fixedDataset.build(), ...englishRecommendedTransformers, }); -const censor = new TextCensor().setStrategy( - keepStartCensorStrategy(asteriskCensorStrategy()) -); +const censor = new TextCensor().setStrategy(fixedPhraseCensorStrategy("🤬")); export const colors = { red, diff --git a/src/util.test.js b/src/util.test.js index db87b46..9147536 100644 --- a/src/util.test.js +++ b/src/util.test.js @@ -83,5 +83,8 @@ describe("bad words filter", () => { expect(badWords.hasMatch("fuck")).toBe(true); expect(badWords.hasMatch("cunting")).toBe(true); expect(badWords.hasMatch("retard")).toBe(true); + expect(badWords.hasMatch("ducks")).toBe(false); + expect(badWords.hasMatch("deck")).toBe(false); + expect(badWords.hasMatch("fickle")).toBe(false); }); });