2Toad / Profanity

A multi-language profanity filter with full TypeScript support
MIT License
80 stars 10 forks source link

Words added to the whitelist are still being censored. #120

Closed Grayy12 closed 2 days ago

Grayy12 commented 4 days ago
const { Profanity, CensorType } = require("@2toad/profanity");
const profanity = new Profanity({
  languages: ["en"],
  wholeWord: true,
  grawlix: "****",
});

profanity.whitelist.addWords(["damn"]);

console.log(profanity.censor("damn", CensorType.Word));

Damn is still censored even though I added it to the whitelist.

Grayy12 commented 4 days ago
const { Profanity, CensorType } = require("@2toad/profanity");
const profanity = new Profanity({
  languages: ["en"],
  wholeWord: true,
  grawlix: "****",
});

profanity.removeWords(["damn"]);

console.log(profanity.censor("damn", CensorType.Word));

I may be using the whitelist wrong, but if I just remove the word, it works.

JasonPierce commented 3 days ago

Thanks for submitting this issue @Grayy12. I'll take a look

JasonPierce commented 3 days ago

Able to reproduce. Working on a fix

Grayy12 commented 3 days ago

Thank you!

JasonPierce commented 2 days ago

Fixed in v3.0.1

const { Profanity, CensorType } = require("@2toad/profanity");
const profanity = new Profanity({
  languages: ["en"],
  wholeWord: true,
  grawlix: "****",
});

// Damn should be replaced with "****"
console.log(profanity.censor("damn", CensorType.Word));
console.log(profanity.censor("This is damn good!", CensorType.Word));

/* Output
----------------------
****
This is **** good!
----------------------
*/

// Damn should not be replaced
profanity.whitelist.addWords(["damn"]);
console.log(profanity.censor("damn", CensorType.Word));
console.log(profanity.censor("This is damn good!", CensorType.Word));

/* Output
----------------------
damn
This is damn good!
----------------------
*/