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

Aurpit bhatiaAurpit bhatia
2 min read

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-checkeris 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


0
Subscribe to my newsletter

Read articles from Aurpit bhatia directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aurpit bhatia
Aurpit bhatia