better-profane-words 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # profane-words-classified
2
+
3
+ A comprehensive list of 2700+ profane words with **category** and **intensity** classifications, ready for content moderation and filtering.
4
+
5
+ Built on top of [profane-words](https://github.com/zautumnz/profane-words).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install profane-words-classified
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ const profanity = require('profane-words-classified');
17
+ ```
18
+
19
+ ### Check if a word is profane
20
+
21
+ ```js
22
+ profanity.isProfane('fuck'); // true
23
+ profanity.isProfane('hello'); // false
24
+ ```
25
+
26
+ ### Look up a word
27
+
28
+ ```js
29
+ profanity.lookup('shit');
30
+ // { word: 'shit', categories: ['bodily'], intensity: 3 }
31
+
32
+ profanity.lookup('ni**er');
33
+ // { word: 'ni**er', categories: ['slur_racial'], intensity: 5 }
34
+ // i censored this to avoid getting cancelled
35
+ ```
36
+
37
+ ### Filter text
38
+
39
+ ```js
40
+ profanity.filterText('what the fuck is this shit');
41
+ // { clean: 'what the *** is this ***', matched: [...] }
42
+
43
+ profanity.filterText('holy damn', { replacement: '[censored]', minIntensity: 2 });
44
+ // { clean: 'holy [censored]', matched: [...] }
45
+ ```
46
+
47
+ ### Check if text contains profanity
48
+
49
+ ```js
50
+ profanity.containsProfanity('this is fine'); // false
51
+ profanity.containsProfanity('what the hell'); // true
52
+
53
+ profanity.containsProfanity('damn it', { minIntensity: 3 }); // false (damn = intensity 1)
54
+ ```
55
+
56
+ ### Get words by category
57
+
58
+ ```js
59
+ profanity.getByCategory('slur_racial'); // all racial slurs
60
+ profanity.getByCategory('drug'); // all drug references
61
+ ```
62
+
63
+ ### Get words by intensity
64
+
65
+ ```js
66
+ profanity.getByIntensity(5); // intensity exactly 5
67
+ profanity.getByIntensity(3, 5); // intensity 3 through 5
68
+ ```
69
+
70
+ ### Get all categories
71
+
72
+ ```js
73
+ profanity.getCategories();
74
+ // ['bodily', 'drug', 'hateful_ideology', 'insult', 'religious', 'sexual', 'slur_gender', 'slur_racial', 'violence']
75
+ ```
76
+
77
+ ## Categories
78
+
79
+ | Category | Description |
80
+ |---|---|
81
+ | `sexual` | Sex acts, sexual anatomy, pornography |
82
+ | `bodily` | Bodily functions and anatomy |
83
+ | `insult` | General insults and name-calling |
84
+ | `slur_racial` | Racial and ethnic slurs |
85
+ | `slur_gender` | Homophobic, transphobic, and sexist slurs |
86
+ | `religious` | Religious profanity |
87
+ | `hateful_ideology` | Nazi, KKK, white supremacy references |
88
+ | `drug` | Drug references |
89
+ | `violence` | Violence and harm references |
90
+
91
+ Words can belong to multiple categories.
92
+
93
+ ## Intensity Scale
94
+
95
+ | Level | Description | Examples |
96
+ |---|---|---|
97
+ | 1 | Mild | crap, damn, ass |
98
+ | 2 | Moderate | bastard, piss, douche |
99
+ | 3 | Strong | fuck, shit, bitch, cock |
100
+ | 4 | Very strong | cunt, motherfucker, rape |
101
+ | 5 | Extremely offensive | Slurs, CSAM references |
102
+
103
+ ## License
104
+
105
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ export interface WordEntry {
2
+ word: string;
3
+ categories: Category[];
4
+ intensity: Intensity;
5
+ }
6
+
7
+ export type Category =
8
+ | 'sexual'
9
+ | 'bodily'
10
+ | 'insult'
11
+ | 'slur_racial'
12
+ | 'slur_gender'
13
+ | 'religious'
14
+ | 'hateful_ideology'
15
+ | 'drug'
16
+ | 'violence';
17
+
18
+ export type Intensity = 1 | 2 | 3 | 4 | 5;
19
+
20
+ export interface FilterOptions {
21
+ replacement?: string;
22
+ minIntensity?: Intensity;
23
+ categories?: Category[];
24
+ }
25
+
26
+ export interface FilterResult {
27
+ clean: string;
28
+ matched: WordEntry[];
29
+ }
30
+
31
+ export declare function isProfane(word: string): boolean;
32
+ export declare function lookup(word: string): WordEntry | null;
33
+ export declare function getByCategory(category: Category): WordEntry[];
34
+ export declare function getByIntensity(min: Intensity, max?: Intensity): WordEntry[];
35
+ export declare function getByIntensityAndCategory(intensity: Intensity, category: Category): WordEntry[];
36
+ export declare function filterText(text: string, options?: FilterOptions): FilterResult;
37
+ export declare function containsProfanity(text: string, options?: FilterOptions): boolean;
38
+ export declare function getCategories(): Category[];
39
+ export declare function getAll(): WordEntry[];
40
+ export declare const words: WordEntry[];
package/index.js ADDED
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ const words = require('./words.json');
4
+
5
+ const _byWord = new Map(words.map(e => [e.word, e]));
6
+
7
+ function isProfane(word) {
8
+ return _byWord.has(word.toLowerCase());
9
+ }
10
+
11
+ function lookup(word) {
12
+ return _byWord.get(word.toLowerCase()) || null;
13
+ }
14
+
15
+ function getByCategory(category) {
16
+ return words.filter(e => e.categories.includes(category));
17
+ }
18
+
19
+ function getByIntensity(min, max) {
20
+ if (max === undefined) max = min;
21
+ return words.filter(e => e.intensity >= min && e.intensity <= max);
22
+ }
23
+
24
+ function getByIntensityAndCategory(intensity, category) {
25
+ return words.filter(e => e.intensity === intensity && e.categories.includes(category));
26
+ }
27
+
28
+ function filterText(text, options = {}) {
29
+ const { replacement = '***', minIntensity = 1, categories = null } = options;
30
+ let result = text;
31
+ const matched = [];
32
+
33
+ const sorted = [...words].sort((a, b) => b.word.length - a.word.length);
34
+
35
+ for (const entry of sorted) {
36
+ if (entry.intensity < minIntensity) continue;
37
+ if (categories && !categories.some(c => entry.categories.includes(c))) continue;
38
+
39
+ const escaped = entry.word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
40
+ const regex = new RegExp(`\\b${escaped}\\b`, 'gi');
41
+ if (regex.test(result)) {
42
+ matched.push(entry);
43
+ result = result.replace(regex, replacement);
44
+ }
45
+ }
46
+
47
+ return { clean: result, matched };
48
+ }
49
+
50
+ function containsProfanity(text, options = {}) {
51
+ const { minIntensity = 1, categories = null } = options;
52
+ const lower = text.toLowerCase();
53
+ return words.some(entry => {
54
+ if (entry.intensity < minIntensity) return false;
55
+ if (categories && !categories.some(c => entry.categories.includes(c))) return false;
56
+ const escaped = entry.word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
57
+ return new RegExp(`\\b${escaped}\\b`, 'i').test(lower);
58
+ });
59
+ }
60
+
61
+ function getCategories() {
62
+ const cats = new Set();
63
+ for (const entry of words) {
64
+ for (const c of entry.categories) cats.add(c);
65
+ }
66
+ return [...cats].sort();
67
+ }
68
+
69
+ function getAll() {
70
+ return words;
71
+ }
72
+
73
+ module.exports = {
74
+ isProfane,
75
+ lookup,
76
+ getByCategory,
77
+ getByIntensity,
78
+ getByIntensityAndCategory,
79
+ filterText,
80
+ containsProfanity,
81
+ getCategories,
82
+ getAll,
83
+ words,
84
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "better-profane-words",
3
+ "version": "1.0.0",
4
+ "description": "A comprehensive list of profane words with category and intensity classifications",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "types": "index.d.ts",
8
+ "files": [
9
+ "index.js",
10
+ "index.d.ts",
11
+ "words.json",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "test": "node test.js"
16
+ },
17
+ "keywords": [
18
+ "profanity",
19
+ "profane",
20
+ "filter",
21
+ "words",
22
+ "classification",
23
+ "moderation",
24
+ "content-filter"
25
+ ],
26
+ "author": "awdev1",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/awdev1/better-profane-words"
31
+ },
32
+ "dependencies": {
33
+ "better-profane-words": "^1.0.0"
34
+ }
35
+ }