Skip to content

Syth-1/bad-words

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

A Typescript library to find and filter bad-words

Note

This project is a Typescript re-implamentation of bad-words optimized for speed!

Installation

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

Usage

import { 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");

Options

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"],
});

Credits


License

MIT License — same as the original bad-words.

About

A Typescript filter for badwords

Topics

Resources

Stars

Watchers

Forks