node-profanity-filter
Version:
A Node.js profanity filter with support for exact matching, obfuscated word detection, and customizable replacement.
64 lines (44 loc) • 1.88 kB
Markdown
A Node.js profanity filter with support for exact matching, obfuscated word detection, and customizable replacement.
- [Installation](
- [Usage](
- [License](
- [Author](
You can install the `node-profanity-filter` package using npm:
```bash
npm install node-profanity-filter
```
```javascript
import { Filter } from 'node-profanity-filter';
const filter = new Filter({
wordBoundaries: true,
normalize: true,
strict: false,
replaceWith: '',
words: ['badword']
});
// true
console.log(filter.isProfane('badword'));
// false
console.log(filter.isProfane('goodword'));
// true
console.log(filter.isProfane('b@dw0rd', {normalize: true}));
// result: {text: "I like your .", matches: string[]}
console.log(filter.replace('I like your badword.'));
// result: {text: "I like your cat.", matches: string[]}
console.log(filter.replace('I like your badword.', 'cat'));
```
| Option | Type | Default | Description |
|-------------------|------------|---------|--------------------------------------------------------------|
| `wordBoundaries` | boolean | false | Match only whole words instead of substrings |
| `normalize` | boolean | true | Normalize common character obfuscations before matching |
| `replaceWith` | string | '' | String to replace detected profane words with |
| `words` | string[] | [ ] | List of words to include in the filter |
Created by [Crytek1012](https://github.com/Crytek1012).
This project is licensed under the [MIT License](LICENSE).