Skip to content

An assortment of Functions which help Filtering Bad Words from Strings.

Notifications You must be signed in to change notification settings

SorerBOT/BadWordsFilter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BadWordsFilter

An assortment of Functions made to assist a user in Filtering Bad Words from Strings.

Usage

Constructor

Attributes
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
  ...
}

Functions

Censor

Attributes
Attribute Type Options Default Required
String String - - True
Example
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 *****"

HasCurse

Attributes
Attribute Type Options Default Required
String String - - True
Example
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

removeWord

Attributes
Attribute Type Options Default Required
String String - - True
Example
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

addWord

Attributes
Attribute Type Options Default Required
String String - - True
Example
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

removeWords

Attributes
Attribute Type Options Default Required
Array Array of Strings - - True
Example
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

addWords

Attributes
Attribute Type Options Default Required
Array Array of Strings - - True
Example
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

setToken

Attributes
Attribute Type Options Default Required
Token char - - True
Example
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 @@@@@"

setData

Attributes
Attribute Type Options Default Required
Object Object of profanities - - True
Example
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"

getData

Attributes
Attribute Type Options Default Required
Example
import BadWordsFiler from "badwordsfilter";

const Filter = new BadWordsFilter();

Filter.setData({"hello": true, "world": true});

Filter.getData(); // {"hello": true, "world": true}

getToken

Attributes
Attribute Type Options Default Required
Example
import BadWordsFiler from "badwordsfilter";

const Filter = new BadWordsFilter();

Filter.setToken('#');

Filter.getToken(); // #

About

An assortment of Functions which help Filtering Bad Words from Strings.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published