glin-profanity 1.1.9 → 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 +160 -46
- package/lib/cjs/data/english.json +43 -15
- package/lib/cjs/filters/Filter.d.ts +14 -7
- package/lib/cjs/filters/Filter.js +101 -76
- package/lib/cjs/filters/Filter.js.map +1 -1
- package/lib/cjs/hooks/useProfanityChecker.d.ts +21 -4
- package/lib/cjs/hooks/useProfanityChecker.js +31 -10
- package/lib/cjs/hooks/useProfanityChecker.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/types.d.ts +15 -3
- package/lib/cjs/types/types.js +8 -0
- package/lib/cjs/types/types.js.map +1 -1
- package/lib/esm/data/english.json +43 -15
- package/lib/esm/filters/Filter.d.ts +14 -7
- package/lib/esm/filters/Filter.js +101 -76
- package/lib/esm/filters/Filter.js.map +1 -1
- package/lib/esm/hooks/useProfanityChecker.d.ts +21 -4
- package/lib/esm/hooks/useProfanityChecker.js +32 -11
- package/lib/esm/hooks/useProfanityChecker.js.map +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/types.d.ts +15 -3
- package/lib/esm/types/types.js +7 -1
- package/lib/esm/types/types.js.map +1 -1
- package/package.json +17 -4
|
@@ -7,34 +7,55 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { useState } from 'react';
|
|
10
|
+
import { useMemo, useState } from 'react';
|
|
11
11
|
import { Filter } from '../filters/Filter';
|
|
12
12
|
import globalWhitelistData from '../data/globalWhitelist.json';
|
|
13
13
|
export const useProfanityChecker = (config) => {
|
|
14
|
+
var _a;
|
|
14
15
|
const [result, setResult] = useState(null);
|
|
15
|
-
const filterConfig =
|
|
16
|
-
|
|
16
|
+
const filterConfig = useMemo(() => {
|
|
17
|
+
var _a;
|
|
18
|
+
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 });
|
|
19
|
+
if (effective.allowObfuscatedMatch && effective.wordBoundaries) {
|
|
20
|
+
console.warn('[Glin-Profanity] Obfuscated match enabled → wordBoundaries will be ignored internally.');
|
|
21
|
+
}
|
|
22
|
+
return effective;
|
|
23
|
+
}, [config]);
|
|
24
|
+
const filter = useMemo(() => new Filter(filterConfig), [filterConfig]);
|
|
17
25
|
const checkText = (text) => {
|
|
26
|
+
var _a;
|
|
18
27
|
const checkResult = filter.checkProfanity(text);
|
|
28
|
+
// Filter based on minSeverity (if provided)
|
|
29
|
+
const filteredWords = (config === null || config === void 0 ? void 0 : config.minSeverity) && checkResult.severityMap
|
|
30
|
+
? checkResult.profaneWords.filter((word) => checkResult.severityMap &&
|
|
31
|
+
checkResult.severityMap[word] >= config.minSeverity)
|
|
32
|
+
: checkResult.profaneWords;
|
|
33
|
+
// Optional auto-replace
|
|
34
|
+
const autoReplaced = (config === null || config === void 0 ? void 0 : config.autoReplace) && checkResult.processedText
|
|
35
|
+
? checkResult.processedText
|
|
36
|
+
: text;
|
|
19
37
|
setResult(checkResult);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
(_a = config === null || config === void 0 ? void 0 : config.customActions) === null || _a === void 0 ? void 0 : _a.call(config, checkResult);
|
|
39
|
+
return Object.assign(Object.assign({}, checkResult), { filteredWords,
|
|
40
|
+
autoReplaced });
|
|
23
41
|
};
|
|
24
42
|
const checkTextAsync = (text) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
43
|
return new Promise((resolve) => {
|
|
26
|
-
const checkResult =
|
|
27
|
-
setResult(checkResult);
|
|
28
|
-
if (config === null || config === void 0 ? void 0 : config.customActions) {
|
|
29
|
-
config.customActions(checkResult);
|
|
30
|
-
}
|
|
44
|
+
const checkResult = checkText(text); // sync call
|
|
31
45
|
resolve(checkResult);
|
|
32
46
|
});
|
|
33
47
|
});
|
|
48
|
+
const isWordProfane = (word) => {
|
|
49
|
+
return filter.checkProfanity(word).containsProfanity;
|
|
50
|
+
};
|
|
51
|
+
const reset = () => setResult(null);
|
|
34
52
|
return {
|
|
35
53
|
result,
|
|
36
54
|
checkText,
|
|
37
55
|
checkTextAsync,
|
|
56
|
+
reset,
|
|
57
|
+
isDirty: (_a = result === null || result === void 0 ? void 0 : result.containsProfanity) !== null && _a !== void 0 ? _a : false,
|
|
58
|
+
isWordProfane,
|
|
38
59
|
};
|
|
39
60
|
};
|
|
40
61
|
//# sourceMappingURL=useProfanityChecker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProfanityChecker.js","sourceRoot":"","sources":["../../../src/hooks/useProfanityChecker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useProfanityChecker.js","sourceRoot":"","sources":["../../../src/hooks/useProfanityChecker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAgB,MAAM,mBAAmB,CAAC;AAEzD,OAAO,mBAAmB,MAAM,8BAA8B,CAAC;AAiB/D,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,YAAY,GAAiB,OAAO,CAAC,GAAG,EAAE;;QAC9C,MAAM,SAAS,mCACV,CAAC,MAA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,WAAW,CAAC,CAAC;QAErC,uCACK,WAAW,KACd,aAAa;YACb,YAAY,IACZ;IACJ,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAO,IAAY,EAAE,EAAE;QAC5C,OAAO,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,EAAE;YACnD,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY;YACjD,OAAO,CAAC,WAAW,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAA,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE;QACrC,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC;IACvD,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEpC,OAAO;QACL,MAAM;QACN,SAAS;QACT,cAAc;QACd,KAAK;QACL,OAAO,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,mCAAI,KAAK;QAC3C,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/esm/types/types.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
export declare enum SeverityLevel {
|
|
2
|
+
Exact = 1,
|
|
3
|
+
Fuzzy = 2,
|
|
4
|
+
Merged = 3
|
|
5
|
+
}
|
|
6
|
+
export type SeverityLabel = keyof typeof SeverityLevel;
|
|
7
|
+
export interface FilteredProfanityResult {
|
|
8
|
+
result: CheckProfanityResult;
|
|
9
|
+
filteredWords: string[];
|
|
10
|
+
}
|
|
1
11
|
export interface CheckProfanityResult {
|
|
2
12
|
containsProfanity: boolean;
|
|
3
13
|
profaneWords: string[];
|
|
4
14
|
processedText?: string;
|
|
5
|
-
severityMap?:
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
severityMap?: Record<string, SeverityLevel>;
|
|
16
|
+
matchContexts?: {
|
|
17
|
+
word: string;
|
|
18
|
+
context: string;
|
|
19
|
+
}[];
|
|
8
20
|
}
|
|
9
21
|
export type Language = 'arabic' | 'chinese' | 'czech' | 'danish' | 'english' | 'esperanto' | 'finnish' | 'french' | 'german' | 'hindi' | 'hungarian' | 'italian' | 'japanese' | 'korean' | 'norwegian' | 'persian' | 'polish' | 'portuguese' | 'russian' | 'turkish' | 'swedish' | 'thai';
|
package/lib/esm/types/types.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/types/types.ts
|
|
2
|
+
export var SeverityLevel;
|
|
3
|
+
(function (SeverityLevel) {
|
|
4
|
+
SeverityLevel[SeverityLevel["Exact"] = 1] = "Exact";
|
|
5
|
+
SeverityLevel[SeverityLevel["Fuzzy"] = 2] = "Fuzzy";
|
|
6
|
+
SeverityLevel[SeverityLevel["Merged"] = 3] = "Merged";
|
|
7
|
+
})(SeverityLevel || (SeverityLevel = {}));
|
|
2
8
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types/types.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,mDAAS,CAAA;IACT,mDAAS,CAAA;IACT,qDAAU,CAAA;AACZ,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glin-profanity",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Glin-Profanity is a lightweight and efficient npm package designed to detect and filter profane language in text inputs across multiple languages. Whether you’re building a chat application, a comment section, or any platform where user-generated content is involved, Glin-Profanity helps you maintain a clean and respectful environment.",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -56,8 +56,21 @@
|
|
|
56
56
|
"profane-word-filter",
|
|
57
57
|
"profane-word-detection",
|
|
58
58
|
"moderation",
|
|
59
|
-
"moderate"
|
|
59
|
+
"moderate",
|
|
60
|
+
"glinr",
|
|
61
|
+
"profanity-checker",
|
|
62
|
+
"profanity-filter",
|
|
63
|
+
"profanity-check",
|
|
64
|
+
"profanity-moderation",
|
|
65
|
+
"profanity-moderation-tool",
|
|
66
|
+
"profanity-moderation-library",
|
|
67
|
+
"profanity-moderation-service",
|
|
68
|
+
"profanity-moderation-api",
|
|
69
|
+
"profanity-moderation-toolkit",
|
|
70
|
+
"profanity-moderation-framework",
|
|
71
|
+
"profanity-moderation-plugin",
|
|
72
|
+
"profanity-moderation-module"
|
|
60
73
|
],
|
|
61
|
-
"author": "
|
|
74
|
+
"author": "glinr",
|
|
62
75
|
"license": "ISC"
|
|
63
|
-
}
|
|
76
|
+
}
|