Clean Your Appโs Language: How to Use bad-word-checker for Profanity Filtering in JavaScript


Whether you're building a messaging app, a blog comment section, or a child-friendly platform, content moderation is a must.
In this tutorial, Iโll show you how to detect and censor bad words in both English and Hindi using a lightweight npm package: bad-word-checker
.
๐ What is itbad-word-checker
?
bad-word-checker
is a zero-dependency JavaScript library that helps you:
Detect offensive words in a string.
Clean or censor those words with masking (like
*
or#
).Add or remove custom words to fit your use case.
Support multilingual filtering (currently English + Hindi).
๐ฆ Installation
Just run:
npm install bad-word-checker
๐ Basic Usage
import BadWords from "bad-word-checker";
const filter = new BadWords();
const text = "This is a damn message!";
console.log(filter.detect(text)); // true
const clean = filter.cleanWords(text);
console.log(clean); // "This is a **** message!"
๐ง Advanced Use Cases
โ Add Custom Words
filter.addWords(["customword", "annoying"]);
โ Remove Words
filter.removeWords(["damn"]);
๐ Get All Bad Words from Text
filter.getBadWordsFromText("You are annoying and stupid.");
// Output: ["annoying", "stupid"]
๐ข Count Bad Words
filter.countBadWords("bad word bad word");
// Output: 2
๐งผ Custom Masking
filter.cleanWords("bad word here", "#");
// Output: "### #### here"
๐ Hindi Support
The package also supports some common Hindi profanities (devnagri and phonetic spellings). You can test this by typing a Hindi phrase with a bad word โ it will still detect and clean it!
๐งช Use Cases
Chat apps
Blog comments
Social platforms
Gaming lobbies
E-learning tools for kids
๐ค Why Use This?
โ Zero dependencies & lightweight
โ Multilingual
โ Fully customizable
โ Easy to integrate into any Node.js or browser-based project
Subscribe to my newsletter
Read articles from Aurpit bhatia directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
