We might’ve encountered at least one offensive comment or come across that one peculiar username that leaves us feeling disgusted (eww) or frustrated (ugh). In today’s instantly evolving digital era, content moderation and filtering are essential to find the middle ground for secure digital space and freedom of expression. If you are a developer and you want to steer away these "bad words" from your application radius using a npm package, use bad-words indeed.
It allows automatic scanning and filtering of text input such as comments, articles, usernames, messages etc. from users.
This package has an extensive list of predefined offensive words & phrases that are generally considered inappropriate or offensive. This list gets updated based on evolving language trends. Beyond that,the package is highly customizable, allowing us to add our own words to the list, specify the replacement characters, and adjust filtering behaviors to align with our application's desired needs.
Installation & Setup
Install the package by running the following command in your terminal:
npm install bad-words --save
const Filter = require('bad-words'); const filter = new Filter();
Below is a list of parameters and methods that you can select to tailor to your specific requirements:
- list: To view the current list of bad words.
- isProfane: To check if the content contains any offensive words.
- clean: To replace the filtered offensive words with asterisks by default.
- Placeholder Overrides: To change the default replacement character asterisk with any other symbol of your choice.
- Regex Overrides: To specify custom regular expressions to target specific words or phrases for replacement or censoring.
- replaceWord: To replace a word with placeHolder characters.
- addWords: To add custom words to the blacklist.
- removeWords: To remove words from the blacklist.
Additionally, check out the source code on the official GitHub repository of this package for more in-depth insights. As you implement this “bad- words” package, remember the middle ground that was mentioned in the beginning. Cheers to responsible content moderation!
Feel free to give your feedback on this article or suggestions about any other packages for Content Filtering in the comments. And don’t be awestruck if some of them mysteriously disappear. IYKYK.