allprofanity 1.1.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 +268 -218
- package/dist/index.d.ts +136 -51
- package/dist/index.js +667 -161
- package/dist/index.js.map +1 -1
- package/dist/languages/bengali-words.js +0 -1
- package/dist/languages/bengali-words.js.map +1 -1
- package/dist/languages/english-words.d.ts +2 -0
- package/dist/languages/english-words.js +256 -0
- package/dist/languages/english-words.js.map +1 -0
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -1,24 +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
|
-
- **
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- **
|
|
20
|
-
- **TypeScript Support
|
|
21
|
-
- **
|
|
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
|
+
---
|
|
22
26
|
|
|
23
27
|
## Installation
|
|
24
28
|
|
|
@@ -26,327 +30,373 @@ A comprehensive multi-language profanity filter for JavaScript/TypeScript applic
|
|
|
26
30
|
npm install allprofanity
|
|
27
31
|
# or
|
|
28
32
|
yarn add allprofanity
|
|
29
|
-
# or
|
|
30
|
-
pnpm add allprofanity
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
import profanity from 'allprofanity';
|
|
35
|
+
---
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
profanity.check('This is a clean sentence.'); // false
|
|
40
|
-
profanity.check('This is a fucking test.'); // true
|
|
41
|
-
profanity.check('यह एक चूतिया परीक्षण है।'); // true (Hindi example)
|
|
42
|
-
profanity.check('Ye ek chutiya test hai.'); // true (Hinglish example)
|
|
37
|
+
## Quick Start
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
profanity
|
|
46
|
-
// => "This is a ****ing test."
|
|
39
|
+
```typescript
|
|
40
|
+
import profanity from 'allprofanity';
|
|
47
41
|
|
|
48
|
-
//
|
|
49
|
-
profanity.
|
|
50
|
-
|
|
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)
|
|
51
47
|
```
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
---
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
## API Reference & Examples
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
### `check(text: string): boolean`
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
Returns `true` if the text contains any profanity.
|
|
56
|
+
|
|
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)
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
---
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
### `detect(text: string): ProfanityDetectionResult`
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
// Default placeholder is "*"
|
|
70
|
-
profanity.clean('This contains bullshit.');
|
|
71
|
-
// => "This contains ********."
|
|
68
|
+
Returns a detailed result:
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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 }>`
|
|
75
|
+
|
|
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}, ...]
|
|
76
83
|
```
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
---
|
|
79
86
|
|
|
80
|
-
|
|
87
|
+
### `clean(text: string, placeholder?: string): string`
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
// Default placeholder is "***"
|
|
84
|
-
profanity.cleanWithWord('This contains bullshit.');
|
|
85
|
-
// => "This contains ***."
|
|
89
|
+
Replace each character of profane words with a placeholder (default: `*`).
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
profanity.
|
|
89
|
-
//
|
|
91
|
+
```typescript
|
|
92
|
+
profanity.clean('This contains bullshit.'); // "This contains ********."
|
|
93
|
+
profanity.clean('This contains bullshit.', '#'); // "This contains ########."
|
|
94
|
+
profanity.clean('यह एक चूतिया परीक्षण है।'); // e.g. "यह एक ***** परीक्षण है।"
|
|
90
95
|
```
|
|
91
96
|
|
|
92
|
-
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
### `cleanWithPlaceholder(text: string, placeholder?: string): string`
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
Replace each profane word with a single placeholder (default: `***`).
|
|
102
|
+
(If the placeholder is omitted, uses `***`.)
|
|
95
103
|
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
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. "यह एक #### परीक्षण है।"
|
|
99
108
|
```
|
|
100
109
|
|
|
110
|
+
---
|
|
111
|
+
|
|
101
112
|
### `add(word: string | string[]): void`
|
|
102
113
|
|
|
103
|
-
|
|
114
|
+
Add a word or an array of words to the profanity filter.
|
|
104
115
|
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
profanity.
|
|
116
|
+
```typescript
|
|
117
|
+
profanity.add('badword123');
|
|
118
|
+
profanity.check('This is badword123.'); // true
|
|
108
119
|
|
|
109
|
-
|
|
110
|
-
profanity.
|
|
120
|
+
profanity.add(['mierda', 'puta']);
|
|
121
|
+
profanity.check('Esto es mierda.'); // true (Spanish)
|
|
122
|
+
profanity.check('Qué puta situación.'); // true
|
|
111
123
|
```
|
|
112
124
|
|
|
125
|
+
---
|
|
126
|
+
|
|
113
127
|
### `remove(word: string | string[]): void`
|
|
114
128
|
|
|
115
|
-
|
|
129
|
+
Remove a word or an array of words from the profanity filter.
|
|
116
130
|
|
|
117
|
-
```
|
|
118
|
-
// Remove a single word
|
|
131
|
+
```typescript
|
|
119
132
|
profanity.remove('bullshit');
|
|
133
|
+
profanity.check('This is bullshit.'); // false
|
|
120
134
|
|
|
121
|
-
|
|
122
|
-
profanity.
|
|
135
|
+
profanity.remove(['mierda', 'puta']);
|
|
136
|
+
profanity.check('Esto es mierda.'); // false
|
|
123
137
|
```
|
|
124
138
|
|
|
125
|
-
|
|
139
|
+
---
|
|
126
140
|
|
|
127
|
-
|
|
141
|
+
### `addToWhitelist(words: string[]): void`
|
|
128
142
|
|
|
129
|
-
|
|
130
|
-
|
|
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']);
|
|
131
151
|
```
|
|
132
152
|
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### `removeFromWhitelist(words: string[]): void`
|
|
156
|
+
|
|
157
|
+
Remove words from the whitelist so they can be detected again.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
profanity.removeFromWhitelist(['anal']);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
133
165
|
### `setPlaceholder(placeholder: string): void`
|
|
134
166
|
|
|
135
|
-
|
|
167
|
+
Set the default placeholder character for `clean()`.
|
|
136
168
|
|
|
137
|
-
```
|
|
138
|
-
// Set "#" as the default placeholder character
|
|
169
|
+
```typescript
|
|
139
170
|
profanity.setPlaceholder('#');
|
|
171
|
+
profanity.clean('This is bullshit.'); // "This is ########."
|
|
172
|
+
profanity.setPlaceholder('*'); // Reset to default
|
|
140
173
|
```
|
|
141
174
|
|
|
142
|
-
|
|
175
|
+
---
|
|
143
176
|
|
|
144
|
-
|
|
177
|
+
### `updateConfig(options: Partial<AllProfanityOptions>): void`
|
|
145
178
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
profanity.check('I'm an analyst at this company.'); // false, even though 'anal' is a profane word
|
|
149
|
-
profanity.check('This is ass and that's bad.'); // true
|
|
150
|
-
```
|
|
179
|
+
Change configuration at runtime.
|
|
180
|
+
Options include: `enableLeetSpeak`, `caseSensitive`, `strictMode`, `detectPartialWords`, `defaultPlaceholder`, `languages`, `whitelistWords`.
|
|
151
181
|
|
|
152
|
-
|
|
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
|
|
187
|
+
```
|
|
153
188
|
|
|
154
|
-
|
|
189
|
+
---
|
|
155
190
|
|
|
156
|
-
|
|
191
|
+
### `loadLanguage(language: string): boolean`
|
|
157
192
|
|
|
158
|
-
|
|
193
|
+
Load a built-in language.
|
|
159
194
|
|
|
160
|
-
|
|
195
|
+
```typescript
|
|
196
|
+
profanity.loadLanguage('french');
|
|
197
|
+
profanity.check('Ce mot est merde.'); // true
|
|
198
|
+
```
|
|
161
199
|
|
|
162
|
-
|
|
200
|
+
---
|
|
163
201
|
|
|
164
|
-
|
|
165
|
-
// Hindi in Devanagari script
|
|
166
|
-
profanity.check('इस वाक्य में लंड शब्द है।'); // true
|
|
202
|
+
### `loadLanguages(languages: string[]): number`
|
|
167
203
|
|
|
168
|
-
|
|
169
|
-
profanity.check('Is vakya mein lund shabd hai.'); // true
|
|
204
|
+
Load multiple built-in languages at once.
|
|
170
205
|
|
|
171
|
-
|
|
172
|
-
profanity.
|
|
206
|
+
```typescript
|
|
207
|
+
profanity.loadLanguages(['english', 'french', 'german']);
|
|
208
|
+
profanity.check('Das ist scheiße.'); // true (German)
|
|
173
209
|
```
|
|
174
210
|
|
|
175
|
-
|
|
211
|
+
---
|
|
176
212
|
|
|
177
|
-
|
|
213
|
+
### `loadIndianLanguages(): number`
|
|
178
214
|
|
|
179
|
-
|
|
180
|
-
// Bengali in Bengali script
|
|
181
|
-
profanity.check('এই বাক্যে বাল শব্দ আছে।'); // true
|
|
215
|
+
Convenience: Load all major Indian language packs.
|
|
182
216
|
|
|
183
|
-
|
|
184
|
-
profanity.
|
|
217
|
+
```typescript
|
|
218
|
+
profanity.loadIndianLanguages();
|
|
219
|
+
profanity.check('यह एक बेंगाली गाली है।'); // true (Bengali)
|
|
220
|
+
profanity.check('This is a Tamil profanity: புண்டை'); // true
|
|
221
|
+
```
|
|
185
222
|
|
|
186
|
-
|
|
187
|
-
profanity.check('ఈ వాక్యంలో పూకు పదం ఉంది.'); // true
|
|
223
|
+
---
|
|
188
224
|
|
|
189
|
-
|
|
190
|
-
import { AllProfanity } from 'allprofanity';
|
|
191
|
-
const filter = new AllProfanity();
|
|
192
|
-
filter.loadIndianLanguages(); // Loads Hindi, Bengali, Tamil, and Telugu
|
|
193
|
-
```
|
|
225
|
+
### `loadCustomDictionary(name: string, words: string[]): void`
|
|
194
226
|
|
|
195
|
-
|
|
227
|
+
Add your own dictionary as an additional language.
|
|
196
228
|
|
|
197
|
-
|
|
229
|
+
```typescript
|
|
230
|
+
profanity.loadCustomDictionary('swedish', ['fan', 'jävla', 'skit']);
|
|
231
|
+
profanity.loadLanguage('swedish');
|
|
232
|
+
profanity.check('Det här är skit.'); // true
|
|
233
|
+
```
|
|
198
234
|
|
|
199
|
-
|
|
200
|
-
// French example
|
|
201
|
-
profanity.check('Cette phrase contient le mot merde.'); // true
|
|
235
|
+
---
|
|
202
236
|
|
|
203
|
-
|
|
204
|
-
profanity.check('Dieser Satz enthält das Wort scheisse.'); // true
|
|
237
|
+
### `getLoadedLanguages(): string[]`
|
|
205
238
|
|
|
206
|
-
|
|
207
|
-
|
|
239
|
+
Returns the names of all currently loaded language packs.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
console.log(profanity.getLoadedLanguages()); // ['english', 'hindi', ...]
|
|
208
243
|
```
|
|
209
244
|
|
|
210
|
-
|
|
245
|
+
---
|
|
211
246
|
|
|
212
|
-
|
|
247
|
+
### `getAvailableLanguages(): string[]`
|
|
213
248
|
|
|
214
|
-
|
|
215
|
-
// Load individual languages
|
|
216
|
-
profanity.loadLanguage('bengali');
|
|
217
|
-
profanity.loadLanguage('tamil');
|
|
218
|
-
profanity.loadLanguage('french');
|
|
249
|
+
Returns the names of all available built-in language packs.
|
|
219
250
|
|
|
220
|
-
|
|
221
|
-
profanity.
|
|
251
|
+
```typescript
|
|
252
|
+
console.log(profanity.getAvailableLanguages());
|
|
253
|
+
// ['english', 'hindi', 'french', 'german', 'spanish', 'bengali', 'tamil', 'telugu']
|
|
254
|
+
```
|
|
222
255
|
|
|
223
|
-
|
|
224
|
-
const availableLanguages = profanity.getAvailableLanguages();
|
|
225
|
-
// => ['hindi', 'bengali', 'tamil', 'telugu', 'french', 'german', 'spanish']
|
|
256
|
+
---
|
|
226
257
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
```
|
|
258
|
+
### `clearList(): void`
|
|
259
|
+
|
|
260
|
+
Remove all loaded languages and dynamic words (start with a clean filter).
|
|
231
261
|
|
|
232
|
-
|
|
262
|
+
```typescript
|
|
263
|
+
profanity.clearList();
|
|
264
|
+
profanity.check('fuck'); // false
|
|
265
|
+
profanity.loadLanguage('english');
|
|
266
|
+
profanity.check('fuck'); // true
|
|
267
|
+
```
|
|
233
268
|
|
|
234
|
-
|
|
269
|
+
---
|
|
235
270
|
|
|
236
|
-
|
|
271
|
+
### `getConfig(): Partial<AllProfanityOptions>`
|
|
237
272
|
|
|
238
|
-
|
|
273
|
+
Get the current configuration.
|
|
239
274
|
|
|
240
|
-
```
|
|
241
|
-
profanity.
|
|
242
|
-
|
|
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
|
+
*/
|
|
243
288
|
```
|
|
244
289
|
|
|
245
|
-
|
|
290
|
+
---
|
|
246
291
|
|
|
247
|
-
|
|
292
|
+
## Severity Levels
|
|
248
293
|
|
|
249
|
-
|
|
294
|
+
Severity reflects the number and variety of detected profanities:
|
|
250
295
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
]);
|
|
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 |
|
|
258
302
|
|
|
259
|
-
|
|
260
|
-
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Language Support
|
|
306
|
+
|
|
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.
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
profanity.check('This is bullshit and चूतिया.'); // true (mixed English/Hindi)
|
|
313
|
+
profanity.check('Ce mot est merde and पागल.'); // true (French/Hindi)
|
|
261
314
|
```
|
|
262
315
|
|
|
263
|
-
|
|
316
|
+
---
|
|
264
317
|
|
|
265
|
-
|
|
318
|
+
## Use Exported Wordlists
|
|
266
319
|
|
|
267
|
-
|
|
268
|
-
import { AllProfanity } from 'allprofanity';
|
|
320
|
+
For sample words in a language (for UIs, admin, etc):
|
|
269
321
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
322
|
+
```typescript
|
|
323
|
+
import { englishBadWords, hindiBadWords } from 'allprofanity';
|
|
324
|
+
console.log(englishBadWords.slice(0, 5)); // ["fuck", "shit", ...]
|
|
273
325
|
```
|
|
274
326
|
|
|
275
|
-
|
|
327
|
+
---
|
|
276
328
|
|
|
277
|
-
|
|
329
|
+
## Security
|
|
278
330
|
|
|
279
|
-
|
|
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`.
|
|
280
334
|
|
|
281
|
-
|
|
282
|
-
// Pre-compile your most used strings for faster checking
|
|
283
|
-
const badWordsList = profanity.list();
|
|
284
|
-
const preCompiledRegex = new RegExp('\\b(' + badWordsList.join('|') + ')\\b', 'i');
|
|
335
|
+
---
|
|
285
336
|
|
|
286
|
-
|
|
287
|
-
return preCompiledRegex.test(text);
|
|
288
|
-
}
|
|
289
|
-
```
|
|
337
|
+
## Full Example
|
|
290
338
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
```javascript
|
|
294
|
-
function moderateContent(content) {
|
|
295
|
-
if (profanity.check(content)) {
|
|
296
|
-
return {
|
|
297
|
-
isApproved: false,
|
|
298
|
-
cleanedContent: profanity.cleanWithWord(content, '[INAPPROPRIATE]'),
|
|
299
|
-
reason: 'Contains profanity'
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
return { isApproved: true, cleanedContent: content };
|
|
303
|
-
}
|
|
304
|
-
```
|
|
339
|
+
```typescript
|
|
340
|
+
import profanity, { ProfanitySeverity } from 'allprofanity';
|
|
305
341
|
|
|
306
|
-
|
|
342
|
+
// Multi-language detection
|
|
343
|
+
profanity.loadLanguages(['english', 'french', 'tamil']);
|
|
344
|
+
console.log(profanity.check('Ce mot est merde.')); // true
|
|
307
345
|
|
|
308
|
-
-
|
|
309
|
-
|
|
310
|
-
- User-generated content platforms
|
|
311
|
-
- Educational software
|
|
312
|
-
- Forums and community platforms
|
|
313
|
-
- Social media content filtering
|
|
314
|
-
- Comment sections
|
|
315
|
-
- Gaming chat filters
|
|
316
|
-
- Email filtering
|
|
317
|
-
- Document processing systems
|
|
346
|
+
// Leet-speak detection
|
|
347
|
+
console.log(profanity.check('You a f#cking a55hole!')); // true
|
|
318
348
|
|
|
319
|
-
|
|
349
|
+
// Whitelisting
|
|
350
|
+
profanity.addToWhitelist(['anal', 'ass']);
|
|
351
|
+
console.log(profanity.check('He is an associate professor.')); // false
|
|
320
352
|
|
|
321
|
-
|
|
353
|
+
// Severity
|
|
354
|
+
const result = profanity.detect('This is fucking bullshit and chutiya.');
|
|
355
|
+
console.log(ProfanitySeverity[result.severity]); // "SEVERE"
|
|
322
356
|
|
|
323
|
-
|
|
357
|
+
// Custom dictionary
|
|
358
|
+
profanity.loadCustomDictionary('pirate', ['barnacle-head', 'landlubber']);
|
|
359
|
+
profanity.loadLanguage('pirate');
|
|
360
|
+
console.log(profanity.check('You barnacle-head!')); // true
|
|
324
361
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
362
|
+
// Placeholder configuration
|
|
363
|
+
profanity.setPlaceholder('#');
|
|
364
|
+
console.log(profanity.clean('This is bullshit.')); // "This is ########."
|
|
365
|
+
profanity.setPlaceholder('*'); // Reset
|
|
366
|
+
```
|
|
330
367
|
|
|
331
|
-
|
|
368
|
+
---
|
|
332
369
|
|
|
333
|
-
|
|
370
|
+
## FAQ
|
|
334
371
|
|
|
335
|
-
|
|
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.
|
|
374
|
+
|
|
375
|
+
**Q: How do I reset the filter?**
|
|
376
|
+
A: Use `clearList()` and reload languages/dictionaries.
|
|
336
377
|
|
|
337
|
-
|
|
378
|
+
**Q: Is this safe for browser and Node.js?**
|
|
379
|
+
A: Yes! AllProfanity is universal.
|
|
338
380
|
|
|
339
|
-
|
|
381
|
+
---
|
|
340
382
|
|
|
341
|
-
|
|
383
|
+
## Roadmap
|
|
342
384
|
|
|
343
|
-
|
|
385
|
+
- More language packs (Arabic, Russian, etc.)
|
|
386
|
+
- Contextual detection & severity scoring
|
|
387
|
+
- Phonetic/typo/obfuscation resilience
|
|
388
|
+
- Plugin system for custom detection
|
|
344
389
|
|
|
345
|
-
|
|
346
|
-
2. Follow the format of the existing word lists
|
|
347
|
-
3. Submit a pull request with your changes
|
|
390
|
+
---
|
|
348
391
|
|
|
349
|
-
##
|
|
392
|
+
## License
|
|
350
393
|
|
|
351
|
-
|
|
394
|
+
MIT — See [LICENSE](https://github.com/ayush-jadaun/allprofanity/blob/main/LICENSE)
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## Contributing
|
|
352
399
|
|
|
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.
|