Skip to content

Commit

Permalink
Unban some innocent words (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoder authored Dec 3, 2024
1 parent 6c3288a commit c7a9363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import animals from "./utils/animals.json";
import moment from "moment";
import {
DataSet,

Check warning on line 4 in src/util.js

View workflow job for this annotation

GitHub Actions / Lint and Test

'DataSet' is defined but never used
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";
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit c7a9363

Please sign in to comment.