An assortment of Functions made to assist a user in Filtering Bad Words from Strings.
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
Token | char | - | - | False |
Data | object | - | - | False |
// import the class
import BadWordsFilter from "badwordsfilter";
const Filter = new BadWordsFilter();
// Tokens defaults to "*"
// Data defaults to https://github.com/SorerBOT/BadWordsFilter/blob/main/Data/english.json
// When using the filter.censor() method, profanities and swear words will be replaced with your token.
// (e.g., for default token "*": "String With Curse" will become "String With *****")
Data Object will be of the following Structure:
{
"curse": true,
"profanity": true,
"swear": true
...
}
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
String | String | - | - | True |
import BadWordsFilter from "badwordsfilter";
const Filter = new BadWordsFilter("*");
const some_string_with_curse = "Some String With Curse";
Filter.censor(some_string_with_curse); // Would return: "Some String With *****"
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
String | String | - | - | True |
import BadWordsFilter from "badwordsfilter";
const Filter = new BadWordsFilter();
const some_string_with_curse = "Some String With Curse";
Filter.hasCurse(some_string_with_curse); // Would return: True
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
String | String | - | - | True |
import BadWordsFilter from "badwordsfilter";
// say the filter censors a word that you do not wish for it to censor:
const Filter = new Filter();
Filter.hasCurse("Curse"); // Would return: True
Filter.removeWord("curse");
Filter.hasCurse("Curse"); // Would now return: False
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
String | String | - | - | True |
import BadWordsFilter from "badwordsfilter";
// say the filter does not censor a word that you do wish for it to censor:
const Filter = new BadWordsFilter();
Filter.hasCurse("Word"); // Would return: False
Filter.removeWord("word");
Filter.hasCurse("Word"); // Would now return: True
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
Array | Array of Strings | - | - | True |
import BadWordsFilter from "badwordsfilter";
// say the filter censors words that you do not wish for it to censor:
const Filter = new BadWordsFilter();
Filter.hasCurse("Curse"); // Would return: True
Filter.hasCurse("AnotherCurse"); // Would return: True
Filter.removeWords(["Curse", "AnotherCurse"]);
Filter.hasCurse("Curse"); // Would now return: False
Filter.hasCurse("AnotherCurse"); // Would now return: False
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
Array | Array of Strings | - | - | True |
import BadWordsFilter from "badwordsfilter";
// say the filter does not censor words that you do wish for it to censor:
const Filter = new BadWordsFilter();
Filter.hasCurse("Word"); // Would return: False
Filter.hasCurse("AnotherWord"); // Would return: False
Filter.addWords(["Word", "AnotherWord"]);
Filter.hasCurse("Word"); // Would now return: True
Filter.hasCurse("AnotherWord"); // Would now return: True
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
Token | char | - | - | True |
import BadWordsFiler from "badwordsfilter";
const Filter = new BadWordsFilter();
const some_string_with_curse = "Some String With Curse";
Filter.censor(some_string_with_curse) // "Some String With *****"
Filter.setToken('@');
Filter.censor(some_string_with_curse) // "Some String With @@@@@"
Attribute | Type | Options | Default | Required |
---|---|---|---|---|
Object | Object of profanities | - | - | True |
import BadWordsFiler from "badwordsfilter";
const Filter = new BadWordsFilter();
const some_string_with_curse = "Hello World";
Filter.censor(some_string_with_curse) // "Some String With *****"
const some_string = "Hello World!";
Filter.censor(some_string); // "Hello World!"
Filter.setData({"hello": true, "world": true});
Filter.censor(some_string); // "***** *****!"
// Note that the old filter will no longer function.
// If you wish to retain the previous object, and only just moddify it slighty:
// (Add / Remove a few words);
// It is recommended to use the Filter.addWords() / Filter.removeWords() functions instead.
Filter.censor(some_string_with_curse) // "Some String With Curse"
Attribute | Type | Options | Default | Required |
---|
import BadWordsFiler from "badwordsfilter";
const Filter = new BadWordsFilter();
Filter.setData({"hello": true, "world": true});
Filter.getData(); // {"hello": true, "world": true}
Attribute | Type | Options | Default | Required |
---|
import BadWordsFiler from "badwordsfilter";
const Filter = new BadWordsFilter();
Filter.setToken('#');
Filter.getToken(); // #