bad-words is a JavaScript library designed for filtering profanity and undesirable words from text. The current stable version is 4.0.0, which ships with TypeScript types and requires a Node.js environment version 8.0.0 or higher, or an ES2016+ compatible browser environment. While the release cadence is not strictly defined, major versions introduce significant changes, such as the removal of global string prototype modifications and the shift to modern class instantiation. Key features include a highly customizable filter that allows for placeholder overrides, advanced regex-based filtering (including multilingual support), the ability to dynamically add or remove words from the blacklist, and the option to instantiate with an empty list for specific use cases. It also incorporates Soundex support for fuzzy word comparisons, providing a robust and flexible solution for content moderation across various applications.
npm install bad-wordsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic instantiation, cleaning text, customizing the placeholder, and dynamically adding words to the filter list.
Instantiate a new Filter class: 'const filter = new Filter(); filter.clean(text);'
Ensure your Node.js environment is v8.0.0 or higher, or use a build step with Babel for browser compatibility.
Always use 'new Filter()' for instantiation, as the factory pattern is no longer supported.
const filter = new Filter({ emptyList: true }); filter.addWords('my-custom-bad-word');Instantiate the Filter class: 'const filter = new Filter(); filter.clean(text);'
Ensure your Node.js project is configured for ESM (e.g., 'type: module' in package.json), or use CommonJS 'const { Filter } = require('bad-words');' for older environments.For CommonJS, use 'const { Filter } = require('bad-words');' or 'const Filter = require('bad-words').Filter;' to correctly get the class from the module's exports.No dependency data recorded yet.