bad-words-es

raw JSON →
1.0.0 verified Fri May 01 auth: no javascript maintenance

A forked JavaScript filter for profanity detection and cleaning, supporting both Spanish ('es') and English words. Current version 1.0.0 is stable but not actively maintained (last release long ago). It extends the original badwords library with a bilingual word list, language selection, custom placeholder/regex options, and methods to add/remove words. Differentiators include bilingual support out of the box and a simple API, though it lacks TypeScript types and uses CommonJS only.

error Cannot find module 'bad-words-es'
cause Package not installed or typo in module name.
fix
Ensure 'npm install bad-words-es' runs and module name is correct.
error Filter is not a constructor
cause Using import instead of require in CommonJS environment.
fix
Use 'const Filter = require('bad-words-es');'
error TypeError: filter.clean is not a function
cause Incorrect instantiation or Filter class not imported properly.
fix
Verify Filter is imported correctly and instantiated: 'const filter = new Filter();'
error Unexpected token 'export'
cause ES module syntax used in a CommonJS file without transpilation.
fix
Use require() syntax instead of import/export.
deprecated Package is not actively maintained; no updates since initial release.
fix Consider using alternatives like 'profanity-filter' or 'msl-word-filter' for active support.
gotcha Only supports CommonJS; cannot be imported with ES module import syntax.
fix Use require() instead of import. If using TypeScript, set esModuleInterop or use a dynamic import.
gotcha No TypeScript type definitions; type safety is not provided.
fix Declare your own module types or use @ts-ignore.
breaking Language selection via options.languages is an array, but default behavior may not work as expected if not specified.
fix Always pass { languages: ['es', 'en'] } to ensure both languages are used.
gotcha The word list may contain false positives or miss certain profanity due to regional variations.
fix Regularly update the blacklist using addWords/removeWords.
npm install bad-words-es
yarn add bad-words-es
pnpm add bad-words-es

Shows how to create a filter with bilingual languages, clean profanity, add custom words, and change placeholder character.

const Filter = require('bad-words-es');
const filter = new Filter({ languages: ['es', 'en'] });
console.log(filter.clean("No seas pendej0")); // "No seas *******"
console.log(filter.clean("Don't be an ash0le")); // "Don't be an ******"

// Add custom words
filter.addWords('custombad');
console.log(filter.clean("That is custombad")); // "That is *********"

// Use placeholder
const customFilter = new Filter({ placeHolder: 'x' });
customFilter.clean("Bad word here"); // "xxx xxxx xxxx"