allprofanity 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -247
- package/dist/index.d.ts +80 -77
- package/dist/index.js +547 -488
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
# AllProfanity
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A blazing-fast, multi-language, enterprise-grade profanity filter for JavaScript/TypeScript with advanced leet-speak normalization, Unicode support, and a robust, modern API.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/allprofanity)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
+
---
|
|
9
|
+
|
|
8
10
|
## Features
|
|
9
11
|
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **Leet
|
|
14
|
-
- **
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- **Zero External Dependencies**: Fully built from scratch for maximum performance and control.
|
|
25
|
-
- **TypeScript Support**: Full TypeScript type definitions included.
|
|
26
|
-
- **Exportable Dictionaries**: Language word lists are exportable for direct use or extension.
|
|
12
|
+
- **Ultra-Fast O(n) Detection:** TRIE-based, single-pass algorithm for massive performance gains over regex/set-based filters.
|
|
13
|
+
- **Multi-Language Support:** Built-in dictionaries for English, Hindi, French, German, Spanish, Bengali, Tamil, Telugu. Load multiple at once.
|
|
14
|
+
- **Multiple Scripts:** Detects profanity in Latin/Roman (Hinglish) and native scripts (e.g., Devanagari, Tamil, Telugu).
|
|
15
|
+
- **Advanced Leet-Speak Normalization:** Detects obfuscated profanities (`f#ck`, `a55hole`, etc.) with context-aware mapping.
|
|
16
|
+
- **Unicode & Punctuation Robustness:** Handles word boundaries and mixed language content with near-zero false positives.
|
|
17
|
+
- **Flexible Cleaning:** Replace matches character-by-character or as whole words, with configurable placeholders.
|
|
18
|
+
- **Custom Dictionaries:** Add/remove words or entire lists at runtime, including your own language packs.
|
|
19
|
+
- **Whitelisting:** Exclude safe words or false positives from detection.
|
|
20
|
+
- **Severity Levels:** Assess how offensive a string is (`MILD`, `MODERATE`, `SEVERE`, `EXTREME`).
|
|
21
|
+
- **No Dictionary Exposure:** For security, the full list of loaded profanities is never exposed.
|
|
22
|
+
- **TypeScript Support:** Typed, documented API and result objects.
|
|
23
|
+
- **Zero 3rd-Party Dependencies:** Only internal code and data.
|
|
24
|
+
|
|
25
|
+
---
|
|
27
26
|
|
|
28
27
|
## Installation
|
|
29
28
|
|
|
@@ -31,366 +30,373 @@ A comprehensive, zero-dependency, multi-language profanity filter for JavaScript
|
|
|
31
30
|
npm install allprofanity
|
|
32
31
|
# or
|
|
33
32
|
yarn add allprofanity
|
|
34
|
-
# or
|
|
35
|
-
pnpm add allprofanity
|
|
36
33
|
```
|
|
37
34
|
|
|
38
|
-
|
|
35
|
+
---
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
import profanity from 'allprofanity';
|
|
42
|
-
|
|
43
|
-
// Check if a string contains profanity
|
|
44
|
-
profanity.check('This is a clean sentence.'); // false
|
|
45
|
-
profanity.check('This is a fucking test.'); // true
|
|
46
|
-
profanity.check('यह एक चूतिया परीक्षण है।'); // true (Hindi example)
|
|
47
|
-
profanity.check('Ye ek chutiya test hai.'); // true (Hinglish example)
|
|
37
|
+
## Quick Start
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
profanity
|
|
51
|
-
// => "This is a ****ing test."
|
|
39
|
+
```typescript
|
|
40
|
+
import profanity from 'allprofanity';
|
|
52
41
|
|
|
53
|
-
//
|
|
54
|
-
profanity.
|
|
55
|
-
|
|
42
|
+
// Simple check
|
|
43
|
+
profanity.check('This is a clean sentence.'); // false
|
|
44
|
+
profanity.check('What the f#ck is this?'); // true (leet-speak detected)
|
|
45
|
+
profanity.check('यह एक चूतिया परीक्षण है।'); // true (Hindi)
|
|
46
|
+
profanity.check('Ye ek chutiya test hai.'); // true (Hinglish Roman script)
|
|
56
47
|
```
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### `check(string: string): boolean`
|
|
49
|
+
---
|
|
61
50
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
profanity.check('This contains bullshit.'); // true
|
|
66
|
-
profanity.check('This is clean.'); // false
|
|
67
|
-
```
|
|
51
|
+
## API Reference & Examples
|
|
68
52
|
|
|
69
|
-
### `
|
|
53
|
+
### `check(text: string): boolean`
|
|
70
54
|
|
|
71
|
-
|
|
55
|
+
Returns `true` if the text contains any profanity.
|
|
72
56
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
// cleanedText: ...,
|
|
79
|
-
// severity: ...,
|
|
80
|
-
// positions: [...]
|
|
81
|
-
// }
|
|
57
|
+
```typescript
|
|
58
|
+
profanity.check('This is a clean sentence.'); // false
|
|
59
|
+
profanity.check('This is a bullshit sentence.'); // true
|
|
60
|
+
profanity.check('What the f#ck is this?'); // true (leet-speak)
|
|
61
|
+
profanity.check('यह एक चूतिया परीक्षण है।'); // true (Hindi)
|
|
82
62
|
```
|
|
83
63
|
|
|
84
|
-
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### `detect(text: string): ProfanityDetectionResult`
|
|
85
67
|
|
|
86
|
-
|
|
68
|
+
Returns a detailed result:
|
|
87
69
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
- `hasProfanity: boolean`
|
|
71
|
+
- `detectedWords: string[]` (actual matched words)
|
|
72
|
+
- `cleanedText: string` (character-masked)
|
|
73
|
+
- `severity: ProfanitySeverity` (`MILD`, `MODERATE`, `SEVERE`, `EXTREME`)
|
|
74
|
+
- `positions: Array<{ word: string, start: number, end: number }>`
|
|
92
75
|
|
|
93
|
-
|
|
94
|
-
profanity.
|
|
95
|
-
//
|
|
76
|
+
```typescript
|
|
77
|
+
const result = profanity.detect('This is fucking bullshit and chutiya.');
|
|
78
|
+
console.log(result.hasProfanity); // true
|
|
79
|
+
console.log(result.detectedWords); // ['fucking', 'bullshit', 'chutiya']
|
|
80
|
+
console.log(result.severity); // 3 (SEVERE)
|
|
81
|
+
console.log(result.cleanedText); // "This is ******* ******** and ******."
|
|
82
|
+
console.log(result.positions); // e.g. [{word: 'fucking', start: 8, end: 15}, ...]
|
|
96
83
|
```
|
|
97
84
|
|
|
98
|
-
|
|
85
|
+
---
|
|
99
86
|
|
|
100
|
-
|
|
87
|
+
### `clean(text: string, placeholder?: string): string`
|
|
101
88
|
|
|
102
|
-
|
|
103
|
-
// Default placeholder is "***"
|
|
104
|
-
profanity.cleanWithWord('This contains bullshit.');
|
|
105
|
-
// => "This contains ***."
|
|
89
|
+
Replace each character of profane words with a placeholder (default: `*`).
|
|
106
90
|
|
|
107
|
-
|
|
108
|
-
profanity.
|
|
109
|
-
//
|
|
91
|
+
```typescript
|
|
92
|
+
profanity.clean('This contains bullshit.'); // "This contains ********."
|
|
93
|
+
profanity.clean('This contains bullshit.', '#'); // "This contains ########."
|
|
94
|
+
profanity.clean('यह एक चूतिया परीक्षण है।'); // e.g. "यह एक ***** परीक्षण है।"
|
|
110
95
|
```
|
|
111
96
|
|
|
112
|
-
|
|
97
|
+
---
|
|
113
98
|
|
|
114
|
-
|
|
99
|
+
### `cleanWithPlaceholder(text: string, placeholder?: string): string`
|
|
115
100
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
101
|
+
Replace each profane word with a single placeholder (default: `***`).
|
|
102
|
+
(If the placeholder is omitted, uses `***`.)
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
profanity.cleanWithPlaceholder('This contains bullshit.'); // "This contains ***."
|
|
106
|
+
profanity.cleanWithPlaceholder('This contains bullshit.', '[CENSORED]'); // "This contains [CENSORED]."
|
|
107
|
+
profanity.cleanWithPlaceholder('यह एक चूतिया परीक्षण है।', '####'); // e.g. "यह एक #### परीक्षण है।"
|
|
119
108
|
```
|
|
120
109
|
|
|
110
|
+
---
|
|
111
|
+
|
|
121
112
|
### `add(word: string | string[]): void`
|
|
122
113
|
|
|
123
|
-
|
|
114
|
+
Add a word or an array of words to the profanity filter.
|
|
124
115
|
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
profanity.
|
|
116
|
+
```typescript
|
|
117
|
+
profanity.add('badword123');
|
|
118
|
+
profanity.check('This is badword123.'); // true
|
|
128
119
|
|
|
129
|
-
|
|
130
|
-
profanity.
|
|
120
|
+
profanity.add(['mierda', 'puta']);
|
|
121
|
+
profanity.check('Esto es mierda.'); // true (Spanish)
|
|
122
|
+
profanity.check('Qué puta situación.'); // true
|
|
131
123
|
```
|
|
132
124
|
|
|
125
|
+
---
|
|
126
|
+
|
|
133
127
|
### `remove(word: string | string[]): void`
|
|
134
128
|
|
|
135
|
-
|
|
129
|
+
Remove a word or an array of words from the profanity filter.
|
|
136
130
|
|
|
137
|
-
```
|
|
138
|
-
// Remove a single word
|
|
131
|
+
```typescript
|
|
139
132
|
profanity.remove('bullshit');
|
|
133
|
+
profanity.check('This is bullshit.'); // false
|
|
140
134
|
|
|
141
|
-
|
|
142
|
-
profanity.
|
|
135
|
+
profanity.remove(['mierda', 'puta']);
|
|
136
|
+
profanity.check('Esto es mierda.'); // false
|
|
143
137
|
```
|
|
144
138
|
|
|
145
|
-
|
|
139
|
+
---
|
|
146
140
|
|
|
147
|
-
|
|
141
|
+
### `addToWhitelist(words: string[]): void`
|
|
148
142
|
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
Whitelist words so they are never flagged as profane.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
profanity.addToWhitelist(['anal', 'ass']);
|
|
147
|
+
profanity.check('He is an associate professor.'); // false
|
|
148
|
+
profanity.check('I work as an analyst.'); // false
|
|
149
|
+
// Remove from whitelist to restore detection
|
|
150
|
+
profanity.removeFromWhitelist(['anal', 'ass']);
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
---
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
### `removeFromWhitelist(words: string[]): void`
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
Remove words from the whitelist so they can be detected again.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
profanity.removeFromWhitelist(['anal']);
|
|
160
161
|
```
|
|
161
162
|
|
|
162
|
-
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
### `setPlaceholder(placeholder: string): void`
|
|
163
166
|
|
|
164
|
-
|
|
167
|
+
Set the default placeholder character for `clean()`.
|
|
165
168
|
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
```typescript
|
|
170
|
+
profanity.setPlaceholder('#');
|
|
171
|
+
profanity.clean('This is bullshit.'); // "This is ########."
|
|
172
|
+
profanity.setPlaceholder('*'); // Reset to default
|
|
169
173
|
```
|
|
170
174
|
|
|
171
|
-
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### `updateConfig(options: Partial<AllProfanityOptions>): void`
|
|
172
178
|
|
|
173
|
-
|
|
179
|
+
Change configuration at runtime.
|
|
180
|
+
Options include: `enableLeetSpeak`, `caseSensitive`, `strictMode`, `detectPartialWords`, `defaultPlaceholder`, `languages`, `whitelistWords`.
|
|
174
181
|
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
```typescript
|
|
183
|
+
profanity.updateConfig({ caseSensitive: true, enableLeetSpeak: false });
|
|
184
|
+
profanity.check('FUCK'); // false (if caseSensitive)
|
|
185
|
+
profanity.updateConfig({ caseSensitive: false, enableLeetSpeak: true });
|
|
186
|
+
profanity.check('f#ck'); // true
|
|
178
187
|
```
|
|
179
188
|
|
|
189
|
+
---
|
|
190
|
+
|
|
180
191
|
### `loadLanguage(language: string): boolean`
|
|
181
192
|
|
|
182
|
-
|
|
193
|
+
Load a built-in language.
|
|
183
194
|
|
|
184
|
-
```
|
|
185
|
-
profanity.loadLanguage('bengali');
|
|
195
|
+
```typescript
|
|
186
196
|
profanity.loadLanguage('french');
|
|
197
|
+
profanity.check('Ce mot est merde.'); // true
|
|
187
198
|
```
|
|
188
199
|
|
|
200
|
+
---
|
|
201
|
+
|
|
189
202
|
### `loadLanguages(languages: string[]): number`
|
|
190
203
|
|
|
191
|
-
|
|
204
|
+
Load multiple built-in languages at once.
|
|
192
205
|
|
|
193
|
-
```
|
|
194
|
-
profanity.loadLanguages(['
|
|
206
|
+
```typescript
|
|
207
|
+
profanity.loadLanguages(['english', 'french', 'german']);
|
|
208
|
+
profanity.check('Das ist scheiße.'); // true (German)
|
|
195
209
|
```
|
|
196
210
|
|
|
211
|
+
---
|
|
212
|
+
|
|
197
213
|
### `loadIndianLanguages(): number`
|
|
198
214
|
|
|
199
|
-
|
|
215
|
+
Convenience: Load all major Indian language packs.
|
|
200
216
|
|
|
201
|
-
```
|
|
217
|
+
```typescript
|
|
202
218
|
profanity.loadIndianLanguages();
|
|
219
|
+
profanity.check('यह एक बेंगाली गाली है।'); // true (Bengali)
|
|
220
|
+
profanity.check('This is a Tamil profanity: புண்டை'); // true
|
|
203
221
|
```
|
|
204
222
|
|
|
223
|
+
---
|
|
224
|
+
|
|
205
225
|
### `loadCustomDictionary(name: string, words: string[]): void`
|
|
206
226
|
|
|
207
|
-
|
|
227
|
+
Add your own dictionary as an additional language.
|
|
208
228
|
|
|
209
|
-
```
|
|
210
|
-
profanity.loadCustomDictionary('
|
|
211
|
-
profanity.loadLanguage('
|
|
229
|
+
```typescript
|
|
230
|
+
profanity.loadCustomDictionary('swedish', ['fan', 'jävla', 'skit']);
|
|
231
|
+
profanity.loadLanguage('swedish');
|
|
232
|
+
profanity.check('Det här är skit.'); // true
|
|
212
233
|
```
|
|
213
234
|
|
|
214
|
-
|
|
235
|
+
---
|
|
215
236
|
|
|
216
|
-
|
|
237
|
+
### `getLoadedLanguages(): string[]`
|
|
217
238
|
|
|
218
|
-
|
|
219
|
-
profanity.addToWhitelist(['anal', 'ass']);
|
|
220
|
-
profanity.removeFromWhitelist(['anal']);
|
|
221
|
-
```
|
|
239
|
+
Returns the names of all currently loaded language packs.
|
|
222
240
|
|
|
223
|
-
|
|
241
|
+
```typescript
|
|
242
|
+
console.log(profanity.getLoadedLanguages()); // ['english', 'hindi', ...]
|
|
243
|
+
```
|
|
224
244
|
|
|
225
|
-
|
|
245
|
+
---
|
|
226
246
|
|
|
227
|
-
### `
|
|
247
|
+
### `getAvailableLanguages(): string[]`
|
|
228
248
|
|
|
229
|
-
|
|
249
|
+
Returns the names of all available built-in language packs.
|
|
230
250
|
|
|
231
|
-
|
|
251
|
+
```typescript
|
|
252
|
+
console.log(profanity.getAvailableLanguages());
|
|
253
|
+
// ['english', 'hindi', 'french', 'german', 'spanish', 'bengali', 'tamil', 'telugu']
|
|
254
|
+
```
|
|
232
255
|
|
|
233
|
-
|
|
256
|
+
---
|
|
234
257
|
|
|
235
|
-
|
|
236
|
-
profanity.check('He is an associate professor.'); // false, even though 'ass' is a profane word
|
|
237
|
-
profanity.check('I\'m an analyst at this company.'); // false, even though 'anal' is a profane word
|
|
238
|
-
profanity.check('This is ass and that\'s bad.'); // true
|
|
239
|
-
```
|
|
258
|
+
### `clearList(): void`
|
|
240
259
|
|
|
241
|
-
|
|
260
|
+
Remove all loaded languages and dynamic words (start with a clean filter).
|
|
242
261
|
|
|
243
|
-
|
|
262
|
+
```typescript
|
|
263
|
+
profanity.clearList();
|
|
264
|
+
profanity.check('fuck'); // false
|
|
265
|
+
profanity.loadLanguage('english');
|
|
266
|
+
profanity.check('fuck'); // true
|
|
267
|
+
```
|
|
244
268
|
|
|
245
|
-
|
|
246
|
-
- **Hindi/Hinglish** (`./languages/hindi-words.js`)
|
|
247
|
-
- **Bengali** (`./languages/bengali-words.js`)
|
|
248
|
-
- **Tamil** (`./languages/tamil-words.js`)
|
|
249
|
-
- **Telugu** (`./languages/telugu-words.js`)
|
|
250
|
-
- **French** (`./languages/french-words.js`)
|
|
251
|
-
- **German** (`./languages/german-words.js`)
|
|
252
|
-
- **Spanish** (`./languages/spanish-words.js`)
|
|
269
|
+
---
|
|
253
270
|
|
|
254
|
-
|
|
271
|
+
### `getConfig(): Partial<AllProfanityOptions>`
|
|
255
272
|
|
|
256
|
-
|
|
273
|
+
Get the current configuration.
|
|
257
274
|
|
|
258
|
-
```
|
|
259
|
-
profanity.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
275
|
+
```typescript
|
|
276
|
+
console.log(profanity.getConfig());
|
|
277
|
+
/*
|
|
278
|
+
{
|
|
279
|
+
defaultPlaceholder: '*',
|
|
280
|
+
enableLeetSpeak: true,
|
|
281
|
+
caseSensitive: false,
|
|
282
|
+
strictMode: false,
|
|
283
|
+
detectPartialWords: false,
|
|
284
|
+
languages: [...],
|
|
285
|
+
whitelistWords: [...]
|
|
286
|
+
}
|
|
287
|
+
*/
|
|
264
288
|
```
|
|
265
289
|
|
|
266
|
-
|
|
290
|
+
---
|
|
267
291
|
|
|
268
|
-
|
|
292
|
+
## Severity Levels
|
|
269
293
|
|
|
270
|
-
|
|
271
|
-
profanity.check('This English sentence has chutiya which is bad.'); // true
|
|
272
|
-
profanity.check('I\'m saying मादरचोद and bullshit in one sentence.'); // true
|
|
273
|
-
```
|
|
294
|
+
Severity reflects the number and variety of detected profanities:
|
|
274
295
|
|
|
275
|
-
|
|
296
|
+
| Level | Enum Value | Description |
|
|
297
|
+
|-----------|------------|-----------------------------------------|
|
|
298
|
+
| MILD | 1 | 1 unique/total word |
|
|
299
|
+
| MODERATE | 2 | 2 unique or total words |
|
|
300
|
+
| SEVERE | 3 | 3 unique/total words |
|
|
301
|
+
| EXTREME | 4 | 4+ unique or 5+ total profane words |
|
|
276
302
|
|
|
277
|
-
|
|
303
|
+
---
|
|
278
304
|
|
|
279
|
-
|
|
280
|
-
profanity.loadLanguage('bengali');
|
|
281
|
-
profanity.loadLanguages(['tamil', 'french']);
|
|
282
|
-
```
|
|
305
|
+
## Language Support
|
|
283
306
|
|
|
284
|
-
|
|
307
|
+
- **Built-in:** English, Hindi, French, German, Spanish, Bengali, Tamil, Telugu
|
|
308
|
+
- **Scripts:** Latin/Roman, Devanagari, Tamil, Telugu, Bengali, etc.
|
|
309
|
+
- **Mixed Content:** Handles mixed-language and code-switched sentences.
|
|
285
310
|
|
|
286
|
-
```
|
|
287
|
-
profanity.
|
|
288
|
-
profanity.
|
|
311
|
+
```typescript
|
|
312
|
+
profanity.check('This is bullshit and चूतिया.'); // true (mixed English/Hindi)
|
|
313
|
+
profanity.check('Ce mot est merde and पागल.'); // true (French/Hindi)
|
|
289
314
|
```
|
|
290
315
|
|
|
291
|
-
|
|
316
|
+
---
|
|
292
317
|
|
|
293
|
-
|
|
318
|
+
## Use Exported Wordlists
|
|
294
319
|
|
|
295
|
-
|
|
320
|
+
For sample words in a language (for UIs, admin, etc):
|
|
296
321
|
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
'customword1',
|
|
301
|
-
'customword2',
|
|
302
|
-
'customword3'
|
|
303
|
-
]);
|
|
322
|
+
```typescript
|
|
323
|
+
import { englishBadWords, hindiBadWords } from 'allprofanity';
|
|
324
|
+
console.log(englishBadWords.slice(0, 5)); // ["fuck", "shit", ...]
|
|
304
325
|
```
|
|
305
326
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
If you need multiple differently-configured filters, import the `AllProfanity` class directly:
|
|
327
|
+
---
|
|
309
328
|
|
|
310
|
-
|
|
311
|
-
import { AllProfanity } from 'allprofanity';
|
|
329
|
+
## Security
|
|
312
330
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
331
|
+
- **No wordlist exposure:** There is no `.list()` function for security and encapsulation. Use exported word arrays for samples.
|
|
332
|
+
- **TRIE-based:** Scales easily to 50,000+ words.
|
|
333
|
+
- **Handles leet-speak:** Catches obfuscated variants like `f#ck`, `a55hole`.
|
|
316
334
|
|
|
317
|
-
|
|
335
|
+
---
|
|
318
336
|
|
|
319
|
-
|
|
337
|
+
## Full Example
|
|
320
338
|
|
|
321
|
-
|
|
339
|
+
```typescript
|
|
340
|
+
import profanity, { ProfanitySeverity } from 'allprofanity';
|
|
322
341
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
342
|
+
// Multi-language detection
|
|
343
|
+
profanity.loadLanguages(['english', 'french', 'tamil']);
|
|
344
|
+
console.log(profanity.check('Ce mot est merde.')); // true
|
|
326
345
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
```
|
|
346
|
+
// Leet-speak detection
|
|
347
|
+
console.log(profanity.check('You a f#cking a55hole!')); // true
|
|
331
348
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
function moderateContent(content) {
|
|
336
|
-
if (profanity.check(content)) {
|
|
337
|
-
return {
|
|
338
|
-
isApproved: false,
|
|
339
|
-
cleanedContent: profanity.cleanWithWord(content, '[INAPPROPRIATE]'),
|
|
340
|
-
reason: 'Contains profanity'
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
return { isApproved: true, cleanedContent: content };
|
|
344
|
-
}
|
|
345
|
-
```
|
|
349
|
+
// Whitelisting
|
|
350
|
+
profanity.addToWhitelist(['anal', 'ass']);
|
|
351
|
+
console.log(profanity.check('He is an associate professor.')); // false
|
|
346
352
|
|
|
347
|
-
|
|
353
|
+
// Severity
|
|
354
|
+
const result = profanity.detect('This is fucking bullshit and chutiya.');
|
|
355
|
+
console.log(ProfanitySeverity[result.severity]); // "SEVERE"
|
|
348
356
|
|
|
349
|
-
|
|
350
|
-
-
|
|
351
|
-
|
|
352
|
-
-
|
|
353
|
-
- Forums and community platforms
|
|
354
|
-
- Social media content filtering
|
|
355
|
-
- Comment sections
|
|
356
|
-
- Gaming chat filters
|
|
357
|
-
- Email filtering
|
|
358
|
-
- Document processing systems
|
|
357
|
+
// Custom dictionary
|
|
358
|
+
profanity.loadCustomDictionary('pirate', ['barnacle-head', 'landlubber']);
|
|
359
|
+
profanity.loadLanguage('pirate');
|
|
360
|
+
console.log(profanity.check('You barnacle-head!')); // true
|
|
359
361
|
|
|
360
|
-
|
|
362
|
+
// Placeholder configuration
|
|
363
|
+
profanity.setPlaceholder('#');
|
|
364
|
+
console.log(profanity.clean('This is bullshit.')); // "This is ########."
|
|
365
|
+
profanity.setPlaceholder('*'); // Reset
|
|
366
|
+
```
|
|
361
367
|
|
|
362
|
-
|
|
368
|
+
---
|
|
363
369
|
|
|
364
|
-
##
|
|
370
|
+
## FAQ
|
|
365
371
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
- Severity levels for different categories of profanity
|
|
369
|
-
- Phonetic matching for evasion attempts
|
|
370
|
-
- Plugin system for custom detection strategies
|
|
372
|
+
**Q: How do I see all loaded profanities?**
|
|
373
|
+
A: For security, the internal word list is not exposed. Use `englishBadWords` etc. for samples.
|
|
371
374
|
|
|
372
|
-
|
|
375
|
+
**Q: How do I reset the filter?**
|
|
376
|
+
A: Use `clearList()` and reload languages/dictionaries.
|
|
373
377
|
|
|
374
|
-
|
|
378
|
+
**Q: Is this safe for browser and Node.js?**
|
|
379
|
+
A: Yes! AllProfanity is universal.
|
|
375
380
|
|
|
376
|
-
|
|
381
|
+
---
|
|
377
382
|
|
|
378
|
-
|
|
383
|
+
## Roadmap
|
|
379
384
|
|
|
380
|
-
|
|
385
|
+
- More language packs (Arabic, Russian, etc.)
|
|
386
|
+
- Contextual detection & severity scoring
|
|
387
|
+
- Phonetic/typo/obfuscation resilience
|
|
388
|
+
- Plugin system for custom detection
|
|
381
389
|
|
|
382
|
-
|
|
390
|
+
---
|
|
383
391
|
|
|
384
|
-
|
|
392
|
+
## License
|
|
385
393
|
|
|
386
|
-
|
|
387
|
-
2. Follow the format of the existing word lists
|
|
388
|
-
3. Submit a pull request with your changes
|
|
394
|
+
MIT — See [LICENSE](https://github.com/ayush-jadaun/allprofanity/blob/main/LICENSE)
|
|
389
395
|
|
|
390
|
-
|
|
396
|
+
---
|
|
391
397
|
|
|
392
|
-
|
|
398
|
+
## Contributing
|
|
393
399
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
400
|
+
We welcome new language packs, detection improvements, and docs!
|
|
401
|
+
To add a new language, create a file in `src/languages/` and export a string array.
|
|
402
|
+
Open a PR or issue for bugs, features, or suggestions.
|