bad-words-plus
raw JSON → 3.0.4 verified Fri May 01 auth: no javascript maintenance
A Node.js profanity filter that extends the original badwords library by allowing the first and/or last letter of filtered words to be displayed. Current stable version is 3.0.4 (2020). No recent updates. Key differentiators: placeholder override, regex customization, add/remove words, empty list instantiation, and firstLetter/lastLetter display options. Requires Node >=12. Compared to alternatives like bad-words (the parent project), bad-words-plus adds these display options but may lag in maintenance.
Common errors
error Error: Could not find module: bad-words-plus ↓
cause Package not installed or not in node_modules
fix
Run 'npm install bad-words-plus'
error TypeError: filter.clean is not a function ↓
cause Using wrong import (e.g., destructuring { Filter })
fix
Use 'import Filter from 'bad-words-plus'' or 'const Filter = require('bad-words-plus')'
error Uncaught TypeError: Cannot read property 'toLowerCase' of undefined ↓
cause Calling clean() or isProfane() without initializing filter
fix
Ensure filter is created: const filter = new Filter({...})
Warnings
gotcha When using emptyList: true, the filter has no built-in bad words, so addWords must be used to add them. ↓
fix Use new Filter({ emptyList: true, list: ['bad', 'word'] })
gotcha The replaceRegex option overrides the default regex that matches characters. If misconfigured, the filter may not detect profanity. ↓
fix Ensure replaceRegex includes all characters you want to replace, e.g., /[A-Za-z0-9가-힣_]/g
deprecated Package last updated in 2020; no recent maintenance. May have unpatched vulnerabilities or compatibility issues with newer Node versions. ↓
fix Consider migrating to actively maintained alternatives like 'bad-words' or 'leo-profanity'.
gotcha The 'list' option in constructor expects an array of strings; passing a single string will not work. ↓
fix Use new Filter({ list: ['word1', 'word2'] })
Install
npm install bad-words-plus yarn add bad-words-plus pnpm add bad-words-plus Imports
- Filter wrong
const Filter = require('bad-words-plus')correctimport Filter from 'bad-words-plus' - Filter (CommonJS) wrong
const { Filter } = require('bad-words-plus')correctconst Filter = require('bad-words-plus') - Filter type wrong
import { FilterOptions } from 'bad-words-plus'correctimport type { FilterOptions } from 'bad-words-plus'
Quickstart
// Quick start: filter profanity with first letter visible
import Filter from 'bad-words-plus';
// Create filter with options
const filter = new Filter({ firstLetter: true, lastLetter: false });
// Clean a string
console.log(filter.clean("Don't be an ash0le")); // "Don't be an a*****"
// Add custom words
filter.addWords('darn', 'heck');
console.log(filter.clean('What the heck!')); // "What the ****!"
// Check if profane
console.log(filter.isProfane('ash0le')); // true