bad-words-br

raw JSON →
3.0.11 verified Fri May 01 auth: no javascript

A JavaScript profanity filter for Brazilian Portuguese, forked from the popular bad-words library. Version 3.0.11 is the latest stable release. It provides a simple API to clean strings by replacing blacklisted words with a placeholder (default '*'). Key differentiators include support for custom placeholders, regex overrides, adding/removing words from the blacklist, and instantiation with an empty list. The package is designed for Node.js (>=8.0.0) and requires an ES2016+ environment or transpiler. It is released under MIT license and follows semantic versioning.

error TypeError: Filter is not a constructor
cause Using default import incorrectly (e.g., import { Filter } from 'bad-words-br').
fix
Use 'import Filter from 'bad-words-br'' or 'const Filter = require('bad-words-br').
error Error: Cannot find module 'bad-words-br'
cause Package not installed or not in node_modules.
fix
Run 'npm install bad-words-br --save'.
error SyntaxError: Unexpected token 'export'
cause Running code in an environment that does not support ES modules (e.g., older Node.js).
fix
Use CommonJS require or upgrade Node.js to version that supports ES modules.
breaking Version 2.0.0 dropped support for Node <8 and requires ES2016+ environment.
fix Update Node.js to >=8.0.0 or use a transpiler like Babel.
deprecated Constructor option 'regex' is deprecated in favor of 'replaceRegex' as of v3.0.0.
fix Use 'replaceRegex' option instead of 'regex'.
gotcha The default placeholder character is '*', not '#' or any other symbol.
fix If you need a different placeholder, set 'placeHolder' option explicitly.
gotcha Calling 'addWords' with multiple arguments adds each word individually, but passing an array requires spread operator.
fix Use filter.addWords(...array) instead of filter.addWords(array).
gotcha The package does not provide TypeScript type definitions; you may need to create your own or use @types/bad-words-br if available.
fix Install @types/bad-words-br or declare module manually.
npm install bad-words-br
yarn add bad-words-br
pnpm add bad-words-br

Shows basic usage: import Filter, instantiate, clean a string, use custom placeholder, check profanity, add/remove words.

import Filter from 'bad-words-br';

const filter = new Filter();
const cleaned = filter.clean('Don\'t be an ash0le');
console.log(cleaned); // "Don't be an ******"

const customFilter = new Filter({ placeHolder: 'x' });
console.log(customFilter.clean('Don\'t be an ash0le')); // "Don't be an xxxxxx"

console.log(filter.isProfane('ash0le')); // true

filter.addWords('foo', 'bar');
console.log(filter.clean('foo bar')); // "*** ***"

filter.removeWords('ash0le');
console.log(filter.clean('Don\'t be an ash0le')); // "Don't be an ash0le"