Note
This project is a Typescript re-implamentation of bad-words optimized for speed!
Note
For ideal installation in your project, it is recommended to use submodules.
- Installing a new submodule:
git submodule add https://github.com/Syth-1/bad-words.git
git submodule update --init
# updating existing submodules to newest commit:
git submodule update --remoteimport { Filter } from "optimized-badwords";
const filter = new Filter();
// Check if a string contains profanity
console.log(filter.isProfane("some bad word here")); // true/false
// Clean a string
console.log(filter.clean("You are a badword!"));
// -> "You are a ******!"
// Add custom words
filter.addWords("mybadword");
// Whitelist (remove) words
filter.removeWords("hell");The Filter constructor accepts configuration options:
interface FilterOptions {
emptyList?: boolean; // start with an empty list
list?: string[]; // add custom bad words
exclude?: string[]; // words to whitelist
placeHolder?: string; // replacement character (default: "*")
regex?: RegExp; // customize how text is preprocessed
replaceRegex?: RegExp; // customize which chars get replaced
chunkSize?: number; // max words per regex chunk (default: 250)
}Example:
const filter = new Filter({
placeHolder: "#",
exclude: ["javascript"],
list: ["anotherBadWord"],
});MIT License — same as the original
bad-words.