npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bad-word-checker

v1.1.0

Published

A comprehensive JavaScript package for detecting, counting, and filtering profane or inappropriate words in text content, with support for both English and Hindi bad words

Downloads

35

Readme

🛑 bad-word-checker

A comprehensive JavaScript package for detecting, counting, and filtering profane or inappropriate words in text content. Supports both English and Hindi bad words out of the box.

npm version npm downloads license

🌟 Why choose bad-word-checker?

  • 🔍 Accurate Detection: Precisely identifies inappropriate language
  • 🌐 Multilingual Support: Built-in support for both English and Hindi profanity
  • ⚙️ Customizable: Easily add or remove words from the detection list
  • 🛡️ Content Protection: Keep your application's content clean and appropriate
  • 🚀 Simple API: Easy to integrate with minimal configuration
  • 🔧 Lightweight: Zero dependencies, minimal impact on your bundle size

📦 Installation

npm install bad-word-checker

🚀 Usage

Basic Usage

import BadWords from "bad-word-checker";

// Initialize with default bad words (English and Hindi)
const badWordsFilter = new BadWords();

// Check if text contains any bad words
const hasBadWords = badWordsFilter.detect(
  "This text might have some bad words"
);
console.log(hasBadWords); // true or false

// Clean bad words from text (replace with asterisks)
const cleanText = badWordsFilter.cleanWords(
  "This text might have some bad words"
);
console.log(cleanText); // "This text might have some *** ***"

Advanced Usage

// Initialize with default words plus custom bad words
const customBadWords = ["custom", "inappropriate", "words"];
const badWordsFilter = new BadWords(customBadWords);

// Add more words to the bad words list
badWordsFilter.addWords(["more", "bad", "words"]);

// Remove words from the bad words list
badWordsFilter.removeWords(["words"]);

// Get all bad words found in text
const foundBadWords = badWordsFilter.getBadWordsFromText(
  "This text has some bad words"
);
console.log(foundBadWords); // ["bad", "words"]

// Count bad words in text
const count = badWordsFilter.countBadWords("This text has some bad words");
console.log(count); // 2

// Check if a specific word is in the bad words list
const isBad = badWordsFilter.hasExactBadWord("bad");
console.log(isBad); // true

// Clean bad words with a custom mask character
const cleanText = badWordsFilter.cleanWords(
  "This text has some bad words",
  "#"
);
console.log(cleanText); // "This text has some ### #####"

📚 API Reference

Constructor

new BadWords((customWords = []));
  • customWords (optional): Array of additional words to be considered inappropriate

Methods

detect(text)

Checks if the given text contains any bad words.

  • Returns: boolean

getBadWordsFromText(text)

Returns an array of all bad words found in the text.

  • Returns: string[]

countBadWords(text)

Returns the count of bad words in the text.

  • Returns: number

addWords(wordsArray = [])

Adds words to the bad words list.

  • wordsArray: Array of words to add

removeWords(wordsArray = [])

Removes words from the bad words list.

  • wordsArray: Array of words to remove

hasExactBadWord(word)

Checks if the exact word is in the bad words list.

  • Returns: boolean

cleanWords(text, maskChar = "*")

Replaces all bad words in the text with the specified mask character.

  • text: The text to clean
  • maskChar: Character used to mask bad words (default: "*")
  • Returns: string

🔍 Use Cases

  • Chat Applications: Filter inappropriate messages
  • User Comments: Moderate user-generated content
  • Social Media: Detect and censor offensive language
  • Children's Applications: Ensure content remains age-appropriate
  • Content Management Systems: Automate content moderation
  • Forums & Message Boards: Maintain community standards

📝 Examples

Filtering User Input

import BadWords from "bad-word-checker";

function handleUserSubmit(userContent) {
  const filter = new BadWords();

  if (filter.detect(userContent)) {
    return {
      success: false,
      message: "Please remove inappropriate language",
      badWordsCount: filter.countBadWords(userContent),
    };
  }

  return {
    success: true,
    content: userContent,
  };
}

Creating a Comment Moderation System

import BadWords from "bad-word-checker";

class CommentModerator {
  constructor() {
    this.filter = new BadWords();
    // Add application-specific words
    this.filter.addWords(["unwanted", "custom", "terms"]);
  }

  moderateComment(comment) {
    // Replace bad words with asterisks
    return this.filter.cleanWords(comment);
  }

  validateComment(comment) {
    const badWordsList = this.filter.getBadWordsFromText(comment);

    if (badWordsList.length > 0) {
      return {
        valid: false,
        reason: "Contains inappropriate words",
        words: badWordsList,
      };
    }

    return { valid: true };
  }
}

📋 License

MIT

👨‍💻 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Made with ❤️ for content moderation