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/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ export { default as spanishBadWords } from "./languages/spanish-words.js";
|
|
|
6
6
|
export { default as bengaliBadWords } from "./languages/bengali-words.js";
|
|
7
7
|
export { default as tamilBadWords } from "./languages/tamil-words.js";
|
|
8
8
|
export { default as teluguBadWords } from "./languages/telugu-words.js";
|
|
9
|
+
/**
|
|
10
|
+
* Logging interface for the library
|
|
11
|
+
*/
|
|
12
|
+
export interface Logger {
|
|
13
|
+
info(message: string): void;
|
|
14
|
+
warn(message: string): void;
|
|
15
|
+
error(message: string): void;
|
|
16
|
+
}
|
|
9
17
|
/**
|
|
10
18
|
* Configuration options for AllProfanity
|
|
11
19
|
*/
|
|
@@ -18,6 +26,7 @@ export interface AllProfanityOptions {
|
|
|
18
26
|
whitelistWords?: string[];
|
|
19
27
|
strictMode?: boolean;
|
|
20
28
|
detectPartialWords?: boolean;
|
|
29
|
+
logger?: Logger;
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
32
|
* Severity levels for profanity detection
|
|
@@ -43,139 +52,129 @@ export interface ProfanityDetectionResult {
|
|
|
43
52
|
}>;
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
46
|
-
* Advanced AllProfanity -
|
|
47
|
-
*
|
|
55
|
+
* Advanced AllProfanity - Fixed profanity filter with multi-language support
|
|
56
|
+
* Addresses all critical issues from the original implementation
|
|
48
57
|
*/
|
|
49
58
|
export declare class AllProfanity {
|
|
50
|
-
private
|
|
51
|
-
private
|
|
59
|
+
private readonly profanityTrie;
|
|
60
|
+
private readonly whitelistSet;
|
|
61
|
+
private readonly loadedLanguages;
|
|
62
|
+
private readonly logger;
|
|
52
63
|
private defaultPlaceholder;
|
|
53
|
-
private loadedLanguages;
|
|
54
|
-
private whitelistSet;
|
|
55
64
|
private enableLeetSpeak;
|
|
56
65
|
private caseSensitive;
|
|
57
66
|
private strictMode;
|
|
58
67
|
private detectPartialWords;
|
|
59
|
-
private readonly
|
|
60
|
-
private readonly
|
|
61
|
-
private readonly
|
|
62
|
-
private readonly commonPrefixes;
|
|
63
|
-
private availableLanguages;
|
|
64
|
-
/**
|
|
65
|
-
* Create a new AllProfanity instance
|
|
66
|
-
* @param options - Configuration options
|
|
67
|
-
*/
|
|
68
|
+
private readonly availableLanguages;
|
|
69
|
+
private readonly leetMappings;
|
|
70
|
+
private readonly dynamicWords;
|
|
68
71
|
constructor(options?: AllProfanityOptions);
|
|
69
72
|
/**
|
|
70
|
-
* Normalize text by converting leet speak to regular characters
|
|
71
|
-
* @param text - Text to normalize
|
|
72
|
-
* @returns Normalized text
|
|
73
|
+
* Normalize text by converting leet speak to regular characters.
|
|
73
74
|
*/
|
|
74
75
|
private normalizeLeetSpeak;
|
|
75
|
-
private escapeRegex;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Properly escape regex special characters
|
|
78
78
|
*/
|
|
79
|
-
private
|
|
79
|
+
private escapeRegex;
|
|
80
80
|
/**
|
|
81
|
-
* Check if
|
|
81
|
+
* Check if a position has word boundaries (for strict mode)
|
|
82
82
|
*/
|
|
83
83
|
private hasWordBoundaries;
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Helper method to verify whole-word matching.
|
|
86
86
|
*/
|
|
87
|
-
private
|
|
87
|
+
private isWholeWord;
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param language - The language to load
|
|
91
|
-
* @returns boolean - True if loaded successfully, false otherwise
|
|
89
|
+
* Check if a match is whitelisted (by actual matched substring and dictionary word)
|
|
92
90
|
*/
|
|
93
|
-
|
|
91
|
+
private isWhitelistedMatch;
|
|
94
92
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param languages - Array of language names to load
|
|
97
|
-
* @returns number - Number of successfully loaded languages
|
|
93
|
+
* Remove overlapping matches, keep only the longest at each start position
|
|
98
94
|
*/
|
|
99
|
-
|
|
95
|
+
private deduplicateMatches;
|
|
100
96
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @returns number - Number of Indian languages loaded
|
|
97
|
+
* Advanced profanity detection using efficient trie-based algorithm
|
|
103
98
|
*/
|
|
104
|
-
|
|
99
|
+
detect(text: string): ProfanityDetectionResult;
|
|
105
100
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @param name - Name to identify this dictionary
|
|
108
|
-
* @param words - Array of profanity words
|
|
101
|
+
* Main matching function, with whole-word logic.
|
|
109
102
|
*/
|
|
110
|
-
|
|
103
|
+
private findMatches;
|
|
111
104
|
/**
|
|
112
|
-
*
|
|
113
|
-
|
|
105
|
+
* Generate cleaned text by replacing profane words (non-overlapping only)
|
|
106
|
+
*/
|
|
107
|
+
private generateCleanedText;
|
|
108
|
+
/**
|
|
109
|
+
* Simple boolean check for profanity
|
|
110
|
+
*/
|
|
111
|
+
check(text: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Clean text with custom placeholder
|
|
114
|
+
*/
|
|
115
|
+
clean(text: string, placeholder?: string): string;
|
|
116
|
+
/**
|
|
117
|
+
* Clean text by replacing each profane word with a single placeholder (word-level)
|
|
118
|
+
*/
|
|
119
|
+
cleanWithPlaceholder(text: string, placeholder?: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* Add word(s) to the profanity list
|
|
122
|
+
*/
|
|
123
|
+
add(word: string | string[]): void;
|
|
124
|
+
/**
|
|
125
|
+
* Remove word(s) from the profanity list
|
|
126
|
+
*/
|
|
127
|
+
remove(word: string | string[]): void;
|
|
128
|
+
/**
|
|
129
|
+
* Add words to whitelist
|
|
114
130
|
*/
|
|
115
131
|
addToWhitelist(words: string[]): void;
|
|
116
132
|
/**
|
|
117
133
|
* Remove words from whitelist
|
|
118
|
-
* @param words - Array of words to remove from whitelist
|
|
119
134
|
*/
|
|
120
135
|
removeFromWhitelist(words: string[]): void;
|
|
121
136
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @param text - The text to analyze
|
|
124
|
-
* @returns ProfanityDetectionResult - Detailed detection results
|
|
137
|
+
* Helper for whitelist checking with correct normalization
|
|
125
138
|
*/
|
|
126
|
-
|
|
139
|
+
private isWhitelisted;
|
|
127
140
|
/**
|
|
128
|
-
*
|
|
129
|
-
* @param string - The string to check
|
|
130
|
-
* @returns boolean - True if profanity found, false otherwise
|
|
141
|
+
* Load a built-in language dictionary
|
|
131
142
|
*/
|
|
132
|
-
|
|
143
|
+
loadLanguage(language: string): boolean;
|
|
133
144
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @param string - The string to clean
|
|
136
|
-
* @param placeholder - Optional custom placeholder
|
|
137
|
-
* @returns string - The cleaned string
|
|
145
|
+
* Load multiple languages at once
|
|
138
146
|
*/
|
|
139
|
-
|
|
147
|
+
loadLanguages(languages: string[]): number;
|
|
140
148
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @param string - The string to clean
|
|
143
|
-
* @param placeholder - The placeholder to use (defaults to '***')
|
|
144
|
-
* @returns string - The cleaned string
|
|
149
|
+
* Load all Indian languages
|
|
145
150
|
*/
|
|
146
|
-
|
|
151
|
+
loadIndianLanguages(): number;
|
|
147
152
|
/**
|
|
148
|
-
*
|
|
149
|
-
* @returns string[] - Array of all profanity words
|
|
153
|
+
* Load a custom dictionary
|
|
150
154
|
*/
|
|
151
|
-
|
|
155
|
+
loadCustomDictionary(name: string, words: string[]): void;
|
|
152
156
|
/**
|
|
153
|
-
* Add word
|
|
154
|
-
* @param word - String or array of strings to add
|
|
157
|
+
* Add a single word to the trie structure
|
|
155
158
|
*/
|
|
156
|
-
|
|
159
|
+
private addWordToTrie;
|
|
157
160
|
/**
|
|
158
|
-
* Remove
|
|
159
|
-
* @param word - String or array of strings to remove
|
|
161
|
+
* Remove overlapping matches, keep only the longest at each start position
|
|
160
162
|
*/
|
|
161
|
-
|
|
163
|
+
private calculateSeverity;
|
|
162
164
|
/**
|
|
163
|
-
* Clear
|
|
165
|
+
* Clear all loaded dictionaries
|
|
164
166
|
*/
|
|
165
167
|
clearList(): void;
|
|
166
168
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param placeholder - Single character to use as placeholder
|
|
169
|
+
* Set placeholder character
|
|
169
170
|
*/
|
|
170
171
|
setPlaceholder(placeholder: string): void;
|
|
171
172
|
/**
|
|
172
|
-
* Get
|
|
173
|
-
* @returns string[] - Array of loaded language names
|
|
173
|
+
* Get loaded languages
|
|
174
174
|
*/
|
|
175
175
|
getLoadedLanguages(): string[];
|
|
176
176
|
/**
|
|
177
|
-
* Get
|
|
178
|
-
* @returns string[] - Array of available language names
|
|
177
|
+
* Get available languages
|
|
179
178
|
*/
|
|
180
179
|
getAvailableLanguages(): string[];
|
|
181
180
|
/**
|
|
@@ -183,7 +182,11 @@ export declare class AllProfanity {
|
|
|
183
182
|
*/
|
|
184
183
|
getConfig(): Partial<AllProfanityOptions>;
|
|
185
184
|
/**
|
|
186
|
-
*
|
|
185
|
+
* Rebuilds the profanity trie from loaded language dictionaries and dynamic words.
|
|
186
|
+
*/
|
|
187
|
+
private rebuildTrie;
|
|
188
|
+
/**
|
|
189
|
+
* Update configuration. Rebuild trie if needed.
|
|
187
190
|
*/
|
|
188
191
|
updateConfig(options: Partial<AllProfanityOptions>): void;
|
|
189
192
|
}
|