glin-profanity 2.1.0 → 2.3.3
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 +205 -55
- package/lib/cjs/packages/js/src/core/index.d.ts +4 -0
- package/lib/cjs/packages/js/src/core/index.js +55 -0
- package/lib/cjs/packages/js/src/core/index.js.map +1 -0
- package/lib/cjs/packages/js/src/core/types.d.ts +20 -0
- package/lib/cjs/packages/js/src/core/types.js +3 -0
- package/lib/cjs/packages/js/src/core/types.js.map +1 -0
- package/lib/cjs/{data → packages/js/src/data}/dictionary.d.ts +1 -0
- package/lib/cjs/packages/js/src/data/dictionary.js +54 -0
- package/lib/cjs/packages/js/src/data/dictionary.js.map +1 -0
- package/lib/cjs/{filters → packages/js/src/filters}/Filter.d.ts +7 -14
- package/lib/cjs/packages/js/src/filters/Filter.js +246 -0
- package/lib/cjs/packages/js/src/filters/Filter.js.map +1 -0
- package/lib/cjs/packages/js/src/hooks/useProfanityChecker.d.ts +11 -0
- package/lib/cjs/packages/js/src/hooks/useProfanityChecker.js +42 -0
- package/lib/cjs/packages/js/src/hooks/useProfanityChecker.js.map +1 -0
- package/lib/cjs/packages/js/src/index.d.ts +12 -0
- package/lib/cjs/packages/js/src/index.js +24 -0
- package/lib/cjs/packages/js/src/index.js.map +1 -0
- package/lib/cjs/packages/js/src/nlp/contextAnalyzer.d.ts +35 -0
- package/lib/cjs/packages/js/src/nlp/contextAnalyzer.js +203 -0
- package/lib/cjs/packages/js/src/nlp/contextAnalyzer.js.map +1 -0
- package/lib/cjs/packages/js/src/types/types.d.ts +56 -0
- package/lib/cjs/packages/js/src/types/types.js +14 -0
- package/lib/cjs/packages/js/src/types/types.js.map +1 -0
- package/lib/cjs/shared/dictionaries/spanish.json +72 -0
- package/lib/esm/packages/js/src/core/index.d.ts +4 -0
- package/lib/esm/packages/js/src/core/index.js +47 -0
- package/lib/esm/packages/js/src/core/index.js.map +1 -0
- package/lib/esm/packages/js/src/core/types.d.ts +20 -0
- package/lib/esm/packages/js/src/core/types.js +2 -0
- package/lib/esm/packages/js/src/core/types.js.map +1 -0
- package/lib/esm/{data → packages/js/src/data}/dictionary.d.ts +1 -0
- package/lib/esm/packages/js/src/data/dictionary.js +49 -0
- package/lib/esm/packages/js/src/data/dictionary.js.map +1 -0
- package/lib/esm/{filters → packages/js/src/filters}/Filter.d.ts +7 -14
- package/lib/esm/packages/js/src/filters/Filter.js +240 -0
- package/lib/esm/packages/js/src/filters/Filter.js.map +1 -0
- package/lib/esm/packages/js/src/hooks/useProfanityChecker.d.ts +11 -0
- package/lib/esm/packages/js/src/hooks/useProfanityChecker.js +38 -0
- package/lib/esm/packages/js/src/hooks/useProfanityChecker.js.map +1 -0
- package/lib/esm/packages/js/src/index.d.ts +12 -0
- package/lib/esm/packages/js/src/index.js +15 -0
- package/lib/esm/packages/js/src/index.js.map +1 -0
- package/lib/esm/packages/js/src/nlp/contextAnalyzer.d.ts +35 -0
- package/lib/esm/packages/js/src/nlp/contextAnalyzer.js +199 -0
- package/lib/esm/packages/js/src/nlp/contextAnalyzer.js.map +1 -0
- package/lib/esm/packages/js/src/types/types.d.ts +56 -0
- package/lib/esm/packages/js/src/types/types.js +11 -0
- package/lib/esm/packages/js/src/types/types.js.map +1 -0
- package/lib/esm/shared/dictionaries/spanish.json +72 -0
- package/package.json +26 -3
- package/lib/cjs/data/dictionary.js +0 -52
- package/lib/cjs/data/dictionary.js.map +0 -1
- package/lib/cjs/filters/Filter.js +0 -162
- package/lib/cjs/filters/Filter.js.map +0 -1
- package/lib/cjs/hooks/useProfanityChecker.d.ts +0 -34
- package/lib/cjs/hooks/useProfanityChecker.js +0 -68
- package/lib/cjs/hooks/useProfanityChecker.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -4
- package/lib/cjs/index.js +0 -10
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/types/types.d.ts +0 -21
- package/lib/cjs/types/types.js +0 -11
- package/lib/cjs/types/types.js.map +0 -1
- package/lib/esm/data/dictionary.js +0 -47
- package/lib/esm/data/dictionary.js.map +0 -1
- package/lib/esm/filters/Filter.js +0 -156
- package/lib/esm/filters/Filter.js.map +0 -1
- package/lib/esm/hooks/useProfanityChecker.d.ts +0 -34
- package/lib/esm/hooks/useProfanityChecker.js +0 -61
- package/lib/esm/hooks/useProfanityChecker.js.map +0 -1
- package/lib/esm/index.d.ts +0 -4
- package/lib/esm/index.js +0 -4
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/types.d.ts +0 -21
- package/lib/esm/types/types.js +0 -8
- package/lib/esm/types/types.js.map +0 -1
- /package/lib/cjs/{data → shared/dictionaries}/Norwegian.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/arabic.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/chinese.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/czech.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/danish.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/english.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/esperanto.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/finnish.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/french.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/german.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/globalWhitelist.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/hindi.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/hungarian.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/italian.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/japanese.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/korean.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/persian.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/polish.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/portuguese.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/russian.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/swedish.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/thai.json +0 -0
- /package/lib/cjs/{data → shared/dictionaries}/turkish.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/Norwegian.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/arabic.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/chinese.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/czech.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/danish.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/english.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/esperanto.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/finnish.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/french.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/german.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/globalWhitelist.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/hindi.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/hungarian.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/italian.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/japanese.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/korean.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/persian.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/polish.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/portuguese.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/russian.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/swedish.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/thai.json +0 -0
- /package/lib/esm/{data → shared/dictionaries}/turkish.json +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for glin-profanity JavaScript/TypeScript package.
|
|
3
|
+
* Unified API that mirrors the Python package structure.
|
|
4
|
+
*/
|
|
5
|
+
/** Severity levels for profanity matches - unified with Python */
|
|
6
|
+
export declare enum SeverityLevel {
|
|
7
|
+
EXACT = 1,
|
|
8
|
+
FUZZY = 2
|
|
9
|
+
}
|
|
10
|
+
/** Supported languages - unified list with Python */
|
|
11
|
+
export type Language = 'arabic' | 'chinese' | 'czech' | 'danish' | 'english' | 'esperanto' | 'finnish' | 'french' | 'german' | 'hindi' | 'hungarian' | 'italian' | 'japanese' | 'korean' | 'norwegian' | 'persian' | 'polish' | 'portuguese' | 'russian' | 'spanish' | 'swedish' | 'thai' | 'turkish';
|
|
12
|
+
/** Represents a profanity match in text - unified with Python */
|
|
13
|
+
export interface Match {
|
|
14
|
+
word: string;
|
|
15
|
+
index: number;
|
|
16
|
+
severity: SeverityLevel;
|
|
17
|
+
contextScore?: number;
|
|
18
|
+
reason?: string;
|
|
19
|
+
isWhitelisted?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Result of profanity check operation - unified field names */
|
|
22
|
+
export interface CheckProfanityResult {
|
|
23
|
+
containsProfanity: boolean;
|
|
24
|
+
profaneWords: string[];
|
|
25
|
+
processedText?: string;
|
|
26
|
+
severityMap?: Record<string, SeverityLevel>;
|
|
27
|
+
matches?: Match[];
|
|
28
|
+
contextScore?: number;
|
|
29
|
+
reason?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Configuration for context-aware filtering - unified with Python */
|
|
32
|
+
export interface ContextAwareConfig {
|
|
33
|
+
enableContextAware?: boolean;
|
|
34
|
+
contextWindow?: number;
|
|
35
|
+
confidenceThreshold?: number;
|
|
36
|
+
domainWhitelists?: Record<string, string[]>;
|
|
37
|
+
}
|
|
38
|
+
/** Main filter configuration options - unified with Python */
|
|
39
|
+
export interface FilterConfig extends ContextAwareConfig {
|
|
40
|
+
languages?: Language[];
|
|
41
|
+
allLanguages?: boolean;
|
|
42
|
+
caseSensitive?: boolean;
|
|
43
|
+
wordBoundaries?: boolean;
|
|
44
|
+
customWords?: string[];
|
|
45
|
+
replaceWith?: string;
|
|
46
|
+
severityLevels?: boolean;
|
|
47
|
+
ignoreWords?: string[];
|
|
48
|
+
logProfanity?: boolean;
|
|
49
|
+
allowObfuscatedMatch?: boolean;
|
|
50
|
+
fuzzyToleranceLevel?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Result with minimum severity filtering */
|
|
53
|
+
export interface FilteredProfanityResult {
|
|
54
|
+
result: CheckProfanityResult;
|
|
55
|
+
filteredWords: string[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for glin-profanity JavaScript/TypeScript package.
|
|
4
|
+
* Unified API that mirrors the Python package structure.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SeverityLevel = void 0;
|
|
8
|
+
/** Severity levels for profanity matches - unified with Python */
|
|
9
|
+
var SeverityLevel;
|
|
10
|
+
(function (SeverityLevel) {
|
|
11
|
+
SeverityLevel[SeverityLevel["EXACT"] = 1] = "EXACT";
|
|
12
|
+
SeverityLevel[SeverityLevel["FUZZY"] = 2] = "FUZZY";
|
|
13
|
+
})(SeverityLevel || (exports.SeverityLevel = SeverityLevel = {}));
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/types/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAkE;AAClE,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,mDAAS,CAAA;IACT,mDAAS,CAAA;AACX,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"words": [
|
|
3
|
+
"sesinato",
|
|
4
|
+
"asno",
|
|
5
|
+
"bastardo",
|
|
6
|
+
"Bollera",
|
|
7
|
+
"Cabron",
|
|
8
|
+
"Cabrón",
|
|
9
|
+
"Caca",
|
|
10
|
+
"Chupada",
|
|
11
|
+
"Chupapollas",
|
|
12
|
+
"Chupetón",
|
|
13
|
+
"concha",
|
|
14
|
+
"Concha de tu madre",
|
|
15
|
+
"Coño",
|
|
16
|
+
"Coprofagía",
|
|
17
|
+
"Culo",
|
|
18
|
+
"Drogas",
|
|
19
|
+
"Esperma",
|
|
20
|
+
"Fiesta de salchichas",
|
|
21
|
+
"Follador",
|
|
22
|
+
"Follar",
|
|
23
|
+
"Gilipichis",
|
|
24
|
+
"Gilipollas",
|
|
25
|
+
"Hacer una paja",
|
|
26
|
+
"Haciendo el amor",
|
|
27
|
+
"Heroína",
|
|
28
|
+
"Hija de puta",
|
|
29
|
+
"Hijaputa",
|
|
30
|
+
"Hijo de puta",
|
|
31
|
+
"Hijoputa",
|
|
32
|
+
"Idiota",
|
|
33
|
+
"Imbécil",
|
|
34
|
+
"infierno",
|
|
35
|
+
"Jilipollas",
|
|
36
|
+
"Kapullo",
|
|
37
|
+
"Lameculos",
|
|
38
|
+
"Maciza",
|
|
39
|
+
"Macizorra",
|
|
40
|
+
"maldito",
|
|
41
|
+
"Mamada",
|
|
42
|
+
"Marica",
|
|
43
|
+
"Maricón",
|
|
44
|
+
"Mariconazo",
|
|
45
|
+
"martillo",
|
|
46
|
+
"Mierda",
|
|
47
|
+
"Nazi",
|
|
48
|
+
"Orina",
|
|
49
|
+
"Pedo",
|
|
50
|
+
"Pervertido",
|
|
51
|
+
"Pezón",
|
|
52
|
+
"Pinche",
|
|
53
|
+
"Pis",
|
|
54
|
+
"Prostituta",
|
|
55
|
+
"Puta",
|
|
56
|
+
"Racista",
|
|
57
|
+
"Ramera",
|
|
58
|
+
"Sádico",
|
|
59
|
+
"Semen",
|
|
60
|
+
"Sexo",
|
|
61
|
+
"Sexo oral",
|
|
62
|
+
"Soplagaitas",
|
|
63
|
+
"Soplapollas",
|
|
64
|
+
"Tetas grandes",
|
|
65
|
+
"Tía buena",
|
|
66
|
+
"Travesti",
|
|
67
|
+
"Trio",
|
|
68
|
+
"Verga",
|
|
69
|
+
"vete a la mierda",
|
|
70
|
+
"Vulva"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ProfanityCheckerConfig, ProfanityCheckResult } from './types';
|
|
2
|
+
export declare function checkProfanity(text: string, config?: ProfanityCheckerConfig): ProfanityCheckResult;
|
|
3
|
+
export declare function checkProfanityAsync(text: string, config?: ProfanityCheckerConfig): Promise<ProfanityCheckResult>;
|
|
4
|
+
export declare function isWordProfane(word: string, config?: ProfanityCheckerConfig): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Filter } from '../filters/Filter';
|
|
11
|
+
import globalWhitelistData from '@shared/dictionaries/globalWhitelist.json';
|
|
12
|
+
function createFilterConfig(config) {
|
|
13
|
+
var _a;
|
|
14
|
+
const effective = Object.assign(Object.assign({}, (config !== null && config !== void 0 ? config : {})), { ignoreWords: globalWhitelistData.whitelist, fuzzyToleranceLevel: (_a = config === null || config === void 0 ? void 0 : config.fuzzyToleranceLevel) !== null && _a !== void 0 ? _a : 0.8 });
|
|
15
|
+
if (effective.allowObfuscatedMatch && effective.wordBoundaries) {
|
|
16
|
+
console.warn('[Glin-Profanity] Obfuscated match enabled → wordBoundaries will be ignored internally.');
|
|
17
|
+
}
|
|
18
|
+
return effective;
|
|
19
|
+
}
|
|
20
|
+
export function checkProfanity(text, config) {
|
|
21
|
+
var _a;
|
|
22
|
+
const filterConfig = createFilterConfig(config);
|
|
23
|
+
const filter = new Filter(filterConfig);
|
|
24
|
+
const checkResult = filter.checkProfanity(text);
|
|
25
|
+
// Filter based on minSeverity (if provided)
|
|
26
|
+
const filteredWords = (config === null || config === void 0 ? void 0 : config.minSeverity) && checkResult.severityMap
|
|
27
|
+
? checkResult.profaneWords.filter((word) => checkResult.severityMap &&
|
|
28
|
+
checkResult.severityMap[word] >= config.minSeverity)
|
|
29
|
+
: checkResult.profaneWords;
|
|
30
|
+
// Optional auto-replace
|
|
31
|
+
const autoReplaced = (config === null || config === void 0 ? void 0 : config.autoReplace) && checkResult.processedText
|
|
32
|
+
? checkResult.processedText
|
|
33
|
+
: text;
|
|
34
|
+
// Custom actions
|
|
35
|
+
(_a = config === null || config === void 0 ? void 0 : config.customActions) === null || _a === void 0 ? void 0 : _a.call(config, checkResult);
|
|
36
|
+
return Object.assign(Object.assign({}, checkResult), { filteredWords,
|
|
37
|
+
autoReplaced });
|
|
38
|
+
}
|
|
39
|
+
export function checkProfanityAsync(text, config) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return Promise.resolve(checkProfanity(text, config));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function isWordProfane(word, config) {
|
|
45
|
+
return checkProfanity(word, config).containsProfanity;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,mBAAmB,CAAC;AAEzD,OAAO,mBAAmB,MAAM,2CAA2C,CAAC;AAE5E,SAAS,kBAAkB,CAAC,MAA+B;;IACzD,MAAM,SAAS,mCACV,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,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,IAAY,EAAE,MAA+B;;QACrF,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;CAAA;AAED,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,MAA+B;IACzE,OAAO,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,iBAAiB,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CheckProfanityResult, Language, SeverityLevel } from '../types/types';
|
|
2
|
+
export interface ProfanityCheckerConfig {
|
|
3
|
+
languages?: Language[];
|
|
4
|
+
allLanguages?: boolean;
|
|
5
|
+
caseSensitive?: boolean;
|
|
6
|
+
wordBoundaries?: boolean;
|
|
7
|
+
customWords?: string[];
|
|
8
|
+
replaceWith?: string;
|
|
9
|
+
severityLevels?: boolean;
|
|
10
|
+
allowObfuscatedMatch?: boolean;
|
|
11
|
+
fuzzyToleranceLevel?: number;
|
|
12
|
+
minSeverity?: SeverityLevel;
|
|
13
|
+
autoReplace?: boolean;
|
|
14
|
+
customActions?: (result: CheckProfanityResult) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface ProfanityCheckResult extends CheckProfanityResult {
|
|
17
|
+
filteredWords: string[];
|
|
18
|
+
autoReplaced: string;
|
|
19
|
+
}
|
|
20
|
+
export type { CheckProfanityResult, Language, SeverityLevel, FilterConfig } from '../types/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/core/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Arabic from '@shared/dictionaries/arabic.json';
|
|
2
|
+
import Chinese from '@shared/dictionaries/chinese.json';
|
|
3
|
+
import Czech from '@shared/dictionaries/czech.json';
|
|
4
|
+
import Danish from '@shared/dictionaries/danish.json';
|
|
5
|
+
import Esperanto from '@shared/dictionaries/esperanto.json';
|
|
6
|
+
import English from '@shared/dictionaries/english.json';
|
|
7
|
+
import Finnish from '@shared/dictionaries/finnish.json';
|
|
8
|
+
import German from '@shared/dictionaries/german.json';
|
|
9
|
+
import Hindi from '@shared/dictionaries/hindi.json';
|
|
10
|
+
import Hungarian from '@shared/dictionaries/hungarian.json';
|
|
11
|
+
import Korean from '@shared/dictionaries/korean.json';
|
|
12
|
+
import Norwegian from '@shared/dictionaries/Norwegian.json';
|
|
13
|
+
import Persian from '@shared/dictionaries/persian.json';
|
|
14
|
+
import Polish from '@shared/dictionaries/polish.json';
|
|
15
|
+
import Portuguese from '@shared/dictionaries/portuguese.json';
|
|
16
|
+
import Russian from '@shared/dictionaries/russian.json';
|
|
17
|
+
import French from '@shared/dictionaries/french.json';
|
|
18
|
+
import Italian from '@shared/dictionaries/italian.json';
|
|
19
|
+
import Japanese from '@shared/dictionaries/japanese.json';
|
|
20
|
+
import Turkish from '@shared/dictionaries/turkish.json';
|
|
21
|
+
import Spanish from '@shared/dictionaries/spanish.json';
|
|
22
|
+
import Swedish from '@shared/dictionaries/swedish.json';
|
|
23
|
+
import Thai from '@shared/dictionaries/thai.json';
|
|
24
|
+
export default {
|
|
25
|
+
arabic: Arabic.words,
|
|
26
|
+
chinese: Chinese.words,
|
|
27
|
+
czech: Czech.words,
|
|
28
|
+
danish: Danish.words,
|
|
29
|
+
english: English.words,
|
|
30
|
+
esperanto: Esperanto.words,
|
|
31
|
+
finnish: Finnish.words,
|
|
32
|
+
french: French.words,
|
|
33
|
+
german: German.words,
|
|
34
|
+
hindi: Hindi.words,
|
|
35
|
+
hungarian: Hungarian.words,
|
|
36
|
+
italian: Italian.words,
|
|
37
|
+
japanese: Japanese.words,
|
|
38
|
+
korean: Korean.words,
|
|
39
|
+
norwegian: Norwegian.words,
|
|
40
|
+
persian: Persian.words,
|
|
41
|
+
polish: Polish.words,
|
|
42
|
+
portuguese: Portuguese.words,
|
|
43
|
+
russian: Russian.words,
|
|
44
|
+
spanish: Spanish.words,
|
|
45
|
+
turkish: Turkish.words,
|
|
46
|
+
swedish: Swedish.words,
|
|
47
|
+
thai: Thai.words,
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=dictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../../../../../src/data/dictionary.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,KAAK,MAAM,iCAAiC,CAAC;AACpD,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,KAAK,MAAM,iCAAiC,CAAC;AACpD,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,UAAU,MAAM,sCAAsC,CAAC;AAC9D,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,QAAQ,MAAM,oCAAoC,CAAC;AAC1D,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,IAAI,MAAM,gCAAgC,CAAC;AAClD,eAAe;IACb,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,KAAK,EAAE,KAAK,CAAC,KAAK;IAClB,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,SAAS,EAAE,SAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,KAAK,EAAE,KAAK,CAAC,KAAK;IAClB,SAAS,EAAE,SAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,QAAQ,EAAE,QAAQ,CAAC,KAAK;IACxB,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,SAAS,EAAE,SAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,MAAM,EAAE,MAAM,CAAC,KAAK;IACpB,UAAU,EAAE,UAAU,CAAC,KAAK;IAC5B,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,IAAI,EAAE,IAAI,CAAC,KAAK;CACjB,CAAC"}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
languages?: Language[];
|
|
4
|
-
allLanguages?: boolean;
|
|
5
|
-
caseSensitive?: boolean;
|
|
6
|
-
wordBoundaries?: boolean;
|
|
7
|
-
customWords?: string[];
|
|
8
|
-
replaceWith?: string;
|
|
9
|
-
severityLevels?: boolean;
|
|
10
|
-
ignoreWords?: string[];
|
|
11
|
-
logProfanity?: boolean;
|
|
12
|
-
allowObfuscatedMatch?: boolean;
|
|
13
|
-
fuzzyToleranceLevel?: number;
|
|
14
|
-
}
|
|
1
|
+
import { CheckProfanityResult, SeverityLevel, FilterConfig } from '../types/types';
|
|
2
|
+
export type { FilterConfig };
|
|
15
3
|
declare class Filter {
|
|
16
4
|
private words;
|
|
17
5
|
private caseSensitive;
|
|
@@ -22,6 +10,11 @@ declare class Filter {
|
|
|
22
10
|
private logProfanity;
|
|
23
11
|
private allowObfuscatedMatch;
|
|
24
12
|
private fuzzyToleranceLevel;
|
|
13
|
+
private enableContextAware;
|
|
14
|
+
private contextWindow;
|
|
15
|
+
private confidenceThreshold;
|
|
16
|
+
private contextAnalyzer?;
|
|
17
|
+
private primaryLanguage;
|
|
25
18
|
constructor(config?: FilterConfig);
|
|
26
19
|
private debugLog;
|
|
27
20
|
private normalizeObfuscated;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import dictionary from '../data/dictionary';
|
|
2
|
+
import { SeverityLevel } from '../types/types';
|
|
3
|
+
import { ContextAnalyzer } from '../nlp/contextAnalyzer';
|
|
4
|
+
class Filter {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
7
|
+
const defaultLanguage = 'english';
|
|
8
|
+
this.enableContextAware = (_a = config === null || config === void 0 ? void 0 : config.enableContextAware) !== null && _a !== void 0 ? _a : false;
|
|
9
|
+
this.contextWindow = (_b = config === null || config === void 0 ? void 0 : config.contextWindow) !== null && _b !== void 0 ? _b : 3;
|
|
10
|
+
this.confidenceThreshold = (_c = config === null || config === void 0 ? void 0 : config.confidenceThreshold) !== null && _c !== void 0 ? _c : 0.7;
|
|
11
|
+
this.primaryLanguage = ((_d = config === null || config === void 0 ? void 0 : config.languages) === null || _d === void 0 ? void 0 : _d[0]) || defaultLanguage;
|
|
12
|
+
if (this.enableContextAware) {
|
|
13
|
+
this.contextAnalyzer = new ContextAnalyzer({
|
|
14
|
+
contextWindow: this.contextWindow,
|
|
15
|
+
language: this.primaryLanguage,
|
|
16
|
+
domainWhitelists: ((_e = config === null || config === void 0 ? void 0 : config.domainWhitelists) === null || _e === void 0 ? void 0 : _e[this.primaryLanguage]) || []
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
let words = [];
|
|
20
|
+
this.caseSensitive = (_f = config === null || config === void 0 ? void 0 : config.caseSensitive) !== null && _f !== void 0 ? _f : false;
|
|
21
|
+
this.allowObfuscatedMatch = (_g = config === null || config === void 0 ? void 0 : config.allowObfuscatedMatch) !== null && _g !== void 0 ? _g : false;
|
|
22
|
+
this.wordBoundaries = (_h = config === null || config === void 0 ? void 0 : config.wordBoundaries) !== null && _h !== void 0 ? _h : !this.allowObfuscatedMatch;
|
|
23
|
+
this.replaceWith = config === null || config === void 0 ? void 0 : config.replaceWith;
|
|
24
|
+
this.severityLevels = (_j = config === null || config === void 0 ? void 0 : config.severityLevels) !== null && _j !== void 0 ? _j : false;
|
|
25
|
+
this.ignoreWords = new Set(((_k = config === null || config === void 0 ? void 0 : config.ignoreWords) === null || _k === void 0 ? void 0 : _k.map((word) => word.toLowerCase())) || []);
|
|
26
|
+
this.logProfanity = (_l = config === null || config === void 0 ? void 0 : config.logProfanity) !== null && _l !== void 0 ? _l : false;
|
|
27
|
+
this.fuzzyToleranceLevel = (_m = config === null || config === void 0 ? void 0 : config.fuzzyToleranceLevel) !== null && _m !== void 0 ? _m : 0.8;
|
|
28
|
+
if (config === null || config === void 0 ? void 0 : config.allLanguages) {
|
|
29
|
+
for (const lang in dictionary) {
|
|
30
|
+
if (dictionary.hasOwnProperty(lang)) {
|
|
31
|
+
words = [...words, ...dictionary[lang]];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const languages = (config === null || config === void 0 ? void 0 : config.languages) || ['english'];
|
|
37
|
+
const languagesChecks = new Set(languages);
|
|
38
|
+
languagesChecks.forEach((lang) => {
|
|
39
|
+
words = [...words, ...dictionary[lang]];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (config === null || config === void 0 ? void 0 : config.customWords) {
|
|
43
|
+
words = [...words, ...config.customWords];
|
|
44
|
+
}
|
|
45
|
+
this.words = new Map(words.map((word) => [word.toLowerCase(), 1]));
|
|
46
|
+
}
|
|
47
|
+
debugLog(...args) {
|
|
48
|
+
if (this.logProfanity) {
|
|
49
|
+
console.log('[glin-profanity]', ...args);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
normalizeObfuscated(text) {
|
|
53
|
+
let normalized = text.replace(/([a-zA-Z])\1{1,}/g, '$1$1');
|
|
54
|
+
const charMap = {
|
|
55
|
+
'@': 'a',
|
|
56
|
+
$: 's',
|
|
57
|
+
'!': 'i',
|
|
58
|
+
'1': 'i',
|
|
59
|
+
'*': '',
|
|
60
|
+
};
|
|
61
|
+
normalized = normalized.replace(/[@$!1*]/g, (m) => charMap[m] || m);
|
|
62
|
+
return normalized;
|
|
63
|
+
}
|
|
64
|
+
getRegex(word) {
|
|
65
|
+
const flags = this.caseSensitive ? 'g' : 'gi';
|
|
66
|
+
const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
67
|
+
const boundary = this.wordBoundaries ? '\\b' : '';
|
|
68
|
+
return new RegExp(`${boundary}${escapedWord}${boundary}`, flags);
|
|
69
|
+
}
|
|
70
|
+
isFuzzyToleranceMatch(word, text) {
|
|
71
|
+
const simplifiedText = text.toLowerCase().replace(/[^a-z]/g, '');
|
|
72
|
+
const simplifiedWord = word.toLowerCase();
|
|
73
|
+
let matchCount = 0;
|
|
74
|
+
let index = 0;
|
|
75
|
+
for (let i = 0; i < simplifiedText.length; i++) {
|
|
76
|
+
if (simplifiedText[i] === simplifiedWord[index]) {
|
|
77
|
+
matchCount++;
|
|
78
|
+
index++;
|
|
79
|
+
if (index === simplifiedWord.length)
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const score = matchCount / simplifiedWord.length;
|
|
84
|
+
return score >= this.fuzzyToleranceLevel;
|
|
85
|
+
}
|
|
86
|
+
evaluateSeverity(word, text) {
|
|
87
|
+
if (this.wordBoundaries && this.getRegex(word).test(text)) {
|
|
88
|
+
return SeverityLevel.EXACT;
|
|
89
|
+
}
|
|
90
|
+
if (this.getRegex(word).test(text))
|
|
91
|
+
return SeverityLevel.EXACT;
|
|
92
|
+
if (this.isFuzzyToleranceMatch(word, text))
|
|
93
|
+
return SeverityLevel.FUZZY;
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
isProfane(value) {
|
|
97
|
+
let input = this.allowObfuscatedMatch
|
|
98
|
+
? this.normalizeObfuscated(value)
|
|
99
|
+
: value;
|
|
100
|
+
for (const word of this.words.keys()) {
|
|
101
|
+
if (!this.ignoreWords.has(word.toLowerCase()) &&
|
|
102
|
+
this.evaluateSeverity(word, input) !== undefined) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
matches(word) {
|
|
109
|
+
return this.isProfane(word);
|
|
110
|
+
}
|
|
111
|
+
checkProfanity(text) {
|
|
112
|
+
// Backward compatibility: if not context-aware, run old logic
|
|
113
|
+
if (!this.enableContextAware) {
|
|
114
|
+
let input = this.allowObfuscatedMatch
|
|
115
|
+
? this.normalizeObfuscated(text)
|
|
116
|
+
: text;
|
|
117
|
+
input = input.toLowerCase();
|
|
118
|
+
const profaneWords = [];
|
|
119
|
+
const severityMap = {};
|
|
120
|
+
for (const dictWord of this.words.keys()) {
|
|
121
|
+
if (this.ignoreWords.has(dictWord.toLowerCase()))
|
|
122
|
+
continue;
|
|
123
|
+
const severity = this.evaluateSeverity(dictWord, input);
|
|
124
|
+
if (severity !== undefined) {
|
|
125
|
+
const regex = this.getRegex(dictWord);
|
|
126
|
+
let match;
|
|
127
|
+
while ((match = regex.exec(input)) !== null) {
|
|
128
|
+
profaneWords.push(match[0]);
|
|
129
|
+
if (severityMap[match[0]] === undefined) {
|
|
130
|
+
severityMap[match[0]] = severity;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let processedText = text;
|
|
136
|
+
if (this.replaceWith && profaneWords.length > 0) {
|
|
137
|
+
const uniqueWords = Array.from(new Set(profaneWords));
|
|
138
|
+
for (const word of uniqueWords) {
|
|
139
|
+
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
140
|
+
const replacementRegex = this.wordBoundaries
|
|
141
|
+
? new RegExp(`\\b${escaped}\\b`, 'gi')
|
|
142
|
+
: new RegExp(escaped, 'gi');
|
|
143
|
+
processedText = processedText.replace(replacementRegex, this.replaceWith);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
containsProfanity: profaneWords.length > 0,
|
|
148
|
+
profaneWords: Array.from(new Set(profaneWords)),
|
|
149
|
+
processedText: this.replaceWith ? processedText : undefined,
|
|
150
|
+
severityMap: this.severityLevels && Object.keys(severityMap).length > 0
|
|
151
|
+
? severityMap
|
|
152
|
+
: undefined,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// Context-aware path
|
|
156
|
+
let input = this.allowObfuscatedMatch
|
|
157
|
+
? this.normalizeObfuscated(text)
|
|
158
|
+
: text;
|
|
159
|
+
input = input.toLowerCase();
|
|
160
|
+
const originalText = text;
|
|
161
|
+
const profaneWords = [];
|
|
162
|
+
const severityMap = {};
|
|
163
|
+
const matches = [];
|
|
164
|
+
for (const dictWord of this.words.keys()) {
|
|
165
|
+
if (this.ignoreWords.has(dictWord.toLowerCase()))
|
|
166
|
+
continue;
|
|
167
|
+
const severity = this.evaluateSeverity(dictWord, input);
|
|
168
|
+
if (severity !== undefined) {
|
|
169
|
+
const regex = this.getRegex(dictWord);
|
|
170
|
+
let match;
|
|
171
|
+
while ((match = regex.exec(input)) !== null) {
|
|
172
|
+
const matchedWord = match[0];
|
|
173
|
+
const matchIndex = match.index;
|
|
174
|
+
const matchObj = {
|
|
175
|
+
word: matchedWord,
|
|
176
|
+
index: matchIndex,
|
|
177
|
+
severity: severity
|
|
178
|
+
};
|
|
179
|
+
if (this.enableContextAware && this.contextAnalyzer) {
|
|
180
|
+
const contextResult = this.contextAnalyzer.analyzeContext(originalText, matchedWord, matchIndex);
|
|
181
|
+
matchObj.contextScore = contextResult.contextScore;
|
|
182
|
+
matchObj.reason = contextResult.reason;
|
|
183
|
+
matchObj.isWhitelisted = contextResult.isWhitelisted;
|
|
184
|
+
if (contextResult.isWhitelisted || (contextResult.contextScore > this.confidenceThreshold)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
profaneWords.push(matchedWord);
|
|
189
|
+
if (severityMap[matchedWord] === undefined) {
|
|
190
|
+
severityMap[matchedWord] = severity;
|
|
191
|
+
}
|
|
192
|
+
matches.push(matchObj);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (profaneWords.length > 0) {
|
|
197
|
+
this.debugLog('Detected:', profaneWords);
|
|
198
|
+
}
|
|
199
|
+
let processedText = text;
|
|
200
|
+
if (this.replaceWith && profaneWords.length > 0) {
|
|
201
|
+
const uniqueWords = Array.from(new Set(profaneWords));
|
|
202
|
+
for (const word of uniqueWords) {
|
|
203
|
+
const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
204
|
+
const replacementRegex = this.wordBoundaries
|
|
205
|
+
? new RegExp(`\\b${escaped}\\b`, 'gi')
|
|
206
|
+
: new RegExp(escaped, 'gi');
|
|
207
|
+
processedText = processedText.replace(replacementRegex, this.replaceWith);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let contextScore;
|
|
211
|
+
if (this.enableContextAware && matches.length > 0) {
|
|
212
|
+
const totalScore = matches.reduce((sum, match) => sum + (match.contextScore || 0.5), 0);
|
|
213
|
+
contextScore = totalScore / matches.length;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
containsProfanity: profaneWords.length > 0,
|
|
217
|
+
profaneWords: Array.from(new Set(profaneWords)),
|
|
218
|
+
processedText: this.replaceWith ? processedText : undefined,
|
|
219
|
+
severityMap: this.severityLevels && Object.keys(severityMap).length > 0 ? severityMap : undefined,
|
|
220
|
+
matches: matches.length > 0 ? matches : undefined,
|
|
221
|
+
contextScore,
|
|
222
|
+
reason: matches.length > 0 ?
|
|
223
|
+
`Found ${matches.length} potential profanity matches` :
|
|
224
|
+
'No profanity detected'
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
checkProfanityWithMinSeverity(text, minSeverity = SeverityLevel.EXACT) {
|
|
228
|
+
const result = this.checkProfanity(text);
|
|
229
|
+
const filteredWords = result.severityMap && result.profaneWords.length > 0
|
|
230
|
+
? result.profaneWords.filter((word) => {
|
|
231
|
+
var _a;
|
|
232
|
+
const severity = (_a = result.severityMap) === null || _a === void 0 ? void 0 : _a[word];
|
|
233
|
+
return typeof severity === 'number' && severity >= minSeverity;
|
|
234
|
+
})
|
|
235
|
+
: [];
|
|
236
|
+
return { filteredWords, result };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
export { Filter };
|
|
240
|
+
//# sourceMappingURL=Filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../../../src/filters/Filter.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAkC,aAAa,EAAuB,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzD,MAAM,MAAM;IAiBV,YAAY,MAAqB;;QAC/B,MAAM,eAAe,GAAa,SAAS,CAAC;QAC5C,IAAI,CAAC,kBAAkB,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,kBAAkB,mCAAI,KAAK,CAAC;QAC9D,IAAI,CAAC,aAAa,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,mCAAI,CAAC,CAAC;QAChD,IAAI,CAAC,mBAAmB,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,mCAAI,GAAG,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AI,EAAE,EAAE;;gBAClC,MAAM,QAAQ,GAAG,MAAA,MAAM,CAAC,WAAW,0CAAG,IAAI,CAAC,CAAC;gBAC5C,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,WAAW,CAAC;YACjE,CAAC,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;QAET,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;CACF;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProfanityCheckerConfig, ProfanityCheckResult } from '../core/types';
|
|
2
|
+
import type { CheckProfanityResult } from '../types/types';
|
|
3
|
+
export type { ProfanityCheckerConfig };
|
|
4
|
+
export declare const useProfanityChecker: (config?: ProfanityCheckerConfig) => {
|
|
5
|
+
result: CheckProfanityResult;
|
|
6
|
+
checkText: (text: string) => ProfanityCheckResult;
|
|
7
|
+
checkTextAsync: (text: string) => Promise<ProfanityCheckResult>;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
isDirty: boolean;
|
|
10
|
+
isWordProfane: (word: string) => boolean;
|
|
11
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { useState, useCallback } from 'react';
|
|
11
|
+
import { checkProfanity, checkProfanityAsync, isWordProfane } from '../core';
|
|
12
|
+
export const useProfanityChecker = (config) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const [result, setResult] = useState(null);
|
|
15
|
+
const checkText = useCallback((text) => {
|
|
16
|
+
const checkResult = checkProfanity(text, config);
|
|
17
|
+
setResult(checkResult);
|
|
18
|
+
return checkResult;
|
|
19
|
+
}, [config]);
|
|
20
|
+
const checkTextAsync = useCallback((text) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const checkResult = yield checkProfanityAsync(text, config);
|
|
22
|
+
setResult(checkResult);
|
|
23
|
+
return checkResult;
|
|
24
|
+
}), [config]);
|
|
25
|
+
const isWordProfaneCallback = useCallback((word) => {
|
|
26
|
+
return isWordProfane(word, config);
|
|
27
|
+
}, [config]);
|
|
28
|
+
const reset = useCallback(() => setResult(null), []);
|
|
29
|
+
return {
|
|
30
|
+
result,
|
|
31
|
+
checkText,
|
|
32
|
+
checkTextAsync,
|
|
33
|
+
reset,
|
|
34
|
+
isDirty: (_a = result === null || result === void 0 ? void 0 : result.containsProfanity) !== null && _a !== void 0 ? _a : false,
|
|
35
|
+
isWordProfane: isWordProfaneCallback,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=useProfanityChecker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProfanityChecker.js","sourceRoot":"","sources":["../../../../../../src/hooks/useProfanityChecker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAM7E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAA+B,EAAE,EAAE;;IACrE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA8B,IAAI,CAAC,CAAC;IAExE,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC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