glin-profanity 3.1.5 → 3.2.2
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 +84 -566
- package/dist/{types-CdDqSZY7.d.cts → Filter-BGcyIAvO.d.ts} +4 -162
- package/dist/{types-CdDqSZY7.d.ts → Filter-D34Wsmrj.d.cts} +4 -162
- package/dist/frameworks/index.cjs +5257 -0
- package/dist/frameworks/index.d.cts +2 -0
- package/dist/frameworks/index.d.ts +2 -0
- package/dist/frameworks/index.js +5252 -0
- package/dist/frameworks/nextjs.cjs +5257 -0
- package/dist/frameworks/nextjs.d.cts +173 -0
- package/dist/frameworks/nextjs.d.ts +173 -0
- package/dist/frameworks/nextjs.js +5252 -0
- package/dist/index.cjs +151 -85
- package/dist/index.d.cts +5 -29
- package/dist/index.d.ts +5 -29
- package/dist/index.js +152 -85
- package/dist/integrations/index.cjs +6110 -0
- package/dist/integrations/index.d.cts +5 -0
- package/dist/integrations/index.d.ts +5 -0
- package/dist/integrations/index.js +6082 -0
- package/dist/integrations/langchain.cjs +5252 -0
- package/dist/integrations/langchain.d.cts +231 -0
- package/dist/integrations/langchain.d.ts +231 -0
- package/dist/integrations/langchain.js +5239 -0
- package/dist/integrations/openai.cjs +5367 -0
- package/dist/integrations/openai.d.cts +167 -0
- package/dist/integrations/openai.d.ts +167 -0
- package/dist/integrations/openai.js +5362 -0
- package/dist/integrations/semantic.cjs +5314 -0
- package/dist/integrations/semantic.d.cts +268 -0
- package/dist/integrations/semantic.d.ts +268 -0
- package/dist/integrations/semantic.js +5309 -0
- package/dist/integrations/vercel-ai.cjs +5282 -0
- package/dist/integrations/vercel-ai.d.cts +224 -0
- package/dist/integrations/vercel-ai.d.ts +224 -0
- package/dist/integrations/vercel-ai.js +5273 -0
- package/dist/ml/index.cjs +358 -56
- package/dist/ml/index.d.cts +5 -2
- package/dist/ml/index.d.ts +5 -2
- package/dist/ml/index.js +354 -57
- package/dist/ml/transformers.cjs +5237 -0
- package/dist/ml/transformers.d.cts +232 -0
- package/dist/ml/transformers.d.ts +232 -0
- package/dist/ml/transformers.js +5231 -0
- package/dist/multimodal/audio.cjs +5269 -0
- package/dist/multimodal/audio.d.cts +255 -0
- package/dist/multimodal/audio.d.ts +255 -0
- package/dist/multimodal/audio.js +5264 -0
- package/dist/multimodal/index.cjs +5432 -0
- package/dist/multimodal/index.d.cts +4 -0
- package/dist/multimodal/index.d.ts +4 -0
- package/dist/multimodal/index.js +5422 -0
- package/dist/multimodal/ocr.cjs +5193 -0
- package/dist/multimodal/ocr.d.cts +157 -0
- package/dist/multimodal/ocr.d.ts +157 -0
- package/dist/multimodal/ocr.js +5187 -0
- package/dist/react.cjs +5133 -0
- package/dist/react.d.cts +13 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +5131 -0
- package/dist/types-B9c_ik4k.d.cts +88 -0
- package/dist/types-B9c_ik4k.d.ts +88 -0
- package/dist/types-BuKh9tvV.d.ts +20 -0
- package/dist/types-Ct_ueYqw.d.cts +76 -0
- package/dist/types-Ct_ueYqw.d.ts +76 -0
- package/dist/types-DI8nzwWc.d.cts +20 -0
- package/package.json +170 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
2
|
-
|
|
3
1
|
// ../../shared/dictionaries/arabic.json
|
|
4
2
|
var arabic_default = {
|
|
5
3
|
words: [
|
|
@@ -535,7 +533,7 @@ var danish_default = {
|
|
|
535
533
|
// ../../shared/dictionaries/dutch.json
|
|
536
534
|
var dutch_default = {
|
|
537
535
|
words: [
|
|
538
|
-
"aardappels
|
|
536
|
+
"aardappels afgieten",
|
|
539
537
|
"achter het raam zitten",
|
|
540
538
|
"afberen",
|
|
541
539
|
"aflebberen",
|
|
@@ -552,7 +550,7 @@ var dutch_default = {
|
|
|
552
550
|
"bagger schijten",
|
|
553
551
|
"balen",
|
|
554
552
|
"bedonderen",
|
|
555
|
-
"
|
|
553
|
+
"befborstel",
|
|
556
554
|
"beffen",
|
|
557
555
|
"bekken",
|
|
558
556
|
"belazeren",
|
|
@@ -561,11 +559,11 @@ var dutch_default = {
|
|
|
561
559
|
"beurt",
|
|
562
560
|
"boemelen",
|
|
563
561
|
"boerelul",
|
|
564
|
-
"
|
|
562
|
+
"boerenpummel",
|
|
565
563
|
"bokkelul",
|
|
566
564
|
"botergeil",
|
|
567
565
|
"broekhoesten",
|
|
568
|
-
"
|
|
566
|
+
"brugpieper",
|
|
569
567
|
"buffelen",
|
|
570
568
|
"buiten de pot piesen",
|
|
571
569
|
"da's kloten van de bok",
|
|
@@ -573,13 +571,13 @@ var dutch_default = {
|
|
|
573
571
|
"de hoer spelen",
|
|
574
572
|
"de hond uitlaten",
|
|
575
573
|
"de koffer induiken",
|
|
576
|
-
"
|
|
574
|
+
"del",
|
|
577
575
|
"de pijp aan maarten geven",
|
|
578
576
|
"de pijp uitgaan",
|
|
579
577
|
"dombo",
|
|
580
|
-
"
|
|
578
|
+
"draaikont",
|
|
581
579
|
"driehoog achter wonen",
|
|
582
|
-
"
|
|
580
|
+
"drol",
|
|
583
581
|
"drooggeiler",
|
|
584
582
|
"droogkloot",
|
|
585
583
|
"een beurt geven",
|
|
@@ -599,7 +597,7 @@ var dutch_default = {
|
|
|
599
597
|
"godverdomme",
|
|
600
598
|
"graftak",
|
|
601
599
|
"gras maaien",
|
|
602
|
-
"
|
|
600
|
+
"gratenkut",
|
|
603
601
|
"greppeldel",
|
|
604
602
|
"griet",
|
|
605
603
|
"hoempert",
|
|
@@ -612,7 +610,7 @@ var dutch_default = {
|
|
|
612
610
|
"huisdealer",
|
|
613
611
|
"johny",
|
|
614
612
|
"kanen",
|
|
615
|
-
"
|
|
613
|
+
"kettingzeug",
|
|
616
614
|
"klaarkomen",
|
|
617
615
|
"klerebeer",
|
|
618
616
|
"klojo",
|
|
@@ -622,22 +620,22 @@ var dutch_default = {
|
|
|
622
620
|
"klootzak",
|
|
623
621
|
"kloten",
|
|
624
622
|
"knor",
|
|
625
|
-
"
|
|
623
|
+
"kont",
|
|
626
624
|
"kontneuken",
|
|
627
625
|
"krentekakker",
|
|
628
626
|
"kut",
|
|
629
627
|
"kuttelikkertje",
|
|
630
|
-
"
|
|
628
|
+
"kwakkie",
|
|
631
629
|
"liefdesgrot",
|
|
632
630
|
"lul",
|
|
633
631
|
"lul-de-behanger",
|
|
634
632
|
"lulhannes",
|
|
635
633
|
"lummel",
|
|
636
634
|
"mafketel",
|
|
637
|
-
"
|
|
635
|
+
"matennaaier",
|
|
638
636
|
"matje",
|
|
639
637
|
"mof",
|
|
640
|
-
"
|
|
638
|
+
"muts",
|
|
641
639
|
"naaien",
|
|
642
640
|
"naakt",
|
|
643
641
|
"neuken",
|
|
@@ -657,9 +655,9 @@ var dutch_default = {
|
|
|
657
655
|
"paal",
|
|
658
656
|
"paardelul",
|
|
659
657
|
"palen",
|
|
660
|
-
"
|
|
658
|
+
"penoze",
|
|
661
659
|
"piesen",
|
|
662
|
-
"
|
|
660
|
+
"pijpbekkie",
|
|
663
661
|
"pijpen",
|
|
664
662
|
"pik",
|
|
665
663
|
"pleurislaaier",
|
|
@@ -674,7 +672,7 @@ var dutch_default = {
|
|
|
674
672
|
"reet",
|
|
675
673
|
"reetridder",
|
|
676
674
|
"reet trappen, voor zijn",
|
|
677
|
-
"
|
|
675
|
+
"remsporen",
|
|
678
676
|
"reutelen",
|
|
679
677
|
"rothoer",
|
|
680
678
|
"rotzak",
|
|
@@ -687,25 +685,25 @@ var dutch_default = {
|
|
|
687
685
|
"schuinsmarcheerder",
|
|
688
686
|
"shit",
|
|
689
687
|
"slempen",
|
|
690
|
-
"
|
|
688
|
+
"slet",
|
|
691
689
|
"sletterig",
|
|
692
690
|
"slik mijn zaad",
|
|
693
|
-
"
|
|
691
|
+
"snol",
|
|
694
692
|
"spuiten",
|
|
695
693
|
"standje",
|
|
696
|
-
"standje-
|
|
694
|
+
"standje-69",
|
|
697
695
|
"stoephoer",
|
|
698
696
|
"stootje",
|
|
699
|
-
"
|
|
700
|
-
"
|
|
697
|
+
"stront",
|
|
698
|
+
"sufferd",
|
|
701
699
|
"tapijtnek",
|
|
702
|
-
"
|
|
700
|
+
"teef",
|
|
703
701
|
"temeier",
|
|
704
702
|
"teringlijer",
|
|
705
703
|
"toeter",
|
|
706
|
-
"
|
|
707
|
-
"
|
|
708
|
-
"trottoir
|
|
704
|
+
"tongzoen",
|
|
705
|
+
"triootje",
|
|
706
|
+
"trottoir prostituee",
|
|
709
707
|
"trottoirteef",
|
|
710
708
|
"vergallen",
|
|
711
709
|
"verkloten",
|
|
@@ -778,6 +776,8 @@ var english_default = {
|
|
|
778
776
|
"2 girls 1 cup",
|
|
779
777
|
"2g1c",
|
|
780
778
|
"a$$",
|
|
779
|
+
"@ss",
|
|
780
|
+
"4ss",
|
|
781
781
|
"acrotomophilia",
|
|
782
782
|
"alabama hot pocket",
|
|
783
783
|
"alaskan pipeline",
|
|
@@ -917,6 +917,10 @@ var english_default = {
|
|
|
917
917
|
"eunuch",
|
|
918
918
|
"f*ck",
|
|
919
919
|
"f@ck",
|
|
920
|
+
"f4ck",
|
|
921
|
+
"fvck",
|
|
922
|
+
"phuck",
|
|
923
|
+
"fuk",
|
|
920
924
|
"faggot",
|
|
921
925
|
"fecal",
|
|
922
926
|
"felch",
|
|
@@ -1098,6 +1102,9 @@ var english_default = {
|
|
|
1098
1102
|
"shemale",
|
|
1099
1103
|
"shibari",
|
|
1100
1104
|
"shit",
|
|
1105
|
+
"sh1t",
|
|
1106
|
+
"$hit",
|
|
1107
|
+
"$h!t",
|
|
1101
1108
|
"shitblimp",
|
|
1102
1109
|
"shithead",
|
|
1103
1110
|
"shitshow",
|
|
@@ -2201,7 +2208,7 @@ var italian_default = {
|
|
|
2201
2208
|
"di merda",
|
|
2202
2209
|
"ditalino",
|
|
2203
2210
|
"duro",
|
|
2204
|
-
"fare una
|
|
2211
|
+
"fare una sega",
|
|
2205
2212
|
"fava",
|
|
2206
2213
|
"femminuccia",
|
|
2207
2214
|
"fica",
|
|
@@ -2449,7 +2456,6 @@ var japanese_default = {
|
|
|
2449
2456
|
"\u7389\u8210\u3081",
|
|
2450
2457
|
"\u7DCA\u7E1B",
|
|
2451
2458
|
"\u8FD1\u89AA\u76F8\u59E6",
|
|
2452
|
-
"\u5ACC\u3044",
|
|
2453
2459
|
"\u5F8C\u80CC\u4F4D",
|
|
2454
2460
|
"\u5408\u610F\u306E\u6027\u4EA4",
|
|
2455
2461
|
"\u62F7\u554F",
|
|
@@ -2462,7 +2468,6 @@ var japanese_default = {
|
|
|
2462
2468
|
"\u5C04\u7CBE",
|
|
2463
2469
|
"\u624B\u30B3\u30AD",
|
|
2464
2470
|
"\u7363\u59E6",
|
|
2465
|
-
"\u5973\u306E\u5B50",
|
|
2466
2471
|
"\u5973\u738B\u69D8",
|
|
2467
2472
|
"\u5973\u5B50\u9AD8\u751F",
|
|
2468
2473
|
"\u5973\u88C5",
|
|
@@ -2539,7 +2544,6 @@ var turkish_default = {
|
|
|
2539
2544
|
"ak",
|
|
2540
2545
|
"akp",
|
|
2541
2546
|
"al a\u011Fz\u0131na",
|
|
2542
|
-
"allah",
|
|
2543
2547
|
"allahs\u0131z",
|
|
2544
2548
|
"am",
|
|
2545
2549
|
"am biti",
|
|
@@ -2634,7 +2638,6 @@ var turkish_default = {
|
|
|
2634
2638
|
"am\u0131n\u0131 s",
|
|
2635
2639
|
"am\u0131s\u0131na",
|
|
2636
2640
|
"am\u0131s\u0131n\u0131",
|
|
2637
|
-
"ana",
|
|
2638
2641
|
"anaaann",
|
|
2639
2642
|
"anal",
|
|
2640
2643
|
"analarn",
|
|
@@ -2766,8 +2769,6 @@ var turkish_default = {
|
|
|
2766
2769
|
"cikar",
|
|
2767
2770
|
"cim",
|
|
2768
2771
|
"cm",
|
|
2769
|
-
"coca cola",
|
|
2770
|
-
"cola",
|
|
2771
2772
|
"dalaks\u0131z",
|
|
2772
2773
|
"dallama",
|
|
2773
2774
|
"daltassak",
|
|
@@ -3565,7 +3566,7 @@ var turkish_default = {
|
|
|
3565
3566
|
// ../../shared/dictionaries/spanish.json
|
|
3566
3567
|
var spanish_default = {
|
|
3567
3568
|
words: [
|
|
3568
|
-
"
|
|
3569
|
+
"asesinato",
|
|
3569
3570
|
"asno",
|
|
3570
3571
|
"bastardo",
|
|
3571
3572
|
"Bollera",
|
|
@@ -3872,6 +3873,34 @@ var GAMING_POSITIVE = /* @__PURE__ */ new Set([
|
|
|
3872
3873
|
"move",
|
|
3873
3874
|
"combo"
|
|
3874
3875
|
]);
|
|
3876
|
+
var GAMING_ACCEPTABLE_WORDS = /* @__PURE__ */ new Set([
|
|
3877
|
+
"kill",
|
|
3878
|
+
"killer",
|
|
3879
|
+
"killed",
|
|
3880
|
+
"killing",
|
|
3881
|
+
"shoot",
|
|
3882
|
+
"shot",
|
|
3883
|
+
"shooting",
|
|
3884
|
+
"die",
|
|
3885
|
+
"dying",
|
|
3886
|
+
"died",
|
|
3887
|
+
"dead",
|
|
3888
|
+
"death",
|
|
3889
|
+
"badass",
|
|
3890
|
+
"sick",
|
|
3891
|
+
"insane",
|
|
3892
|
+
"crazy",
|
|
3893
|
+
"mad",
|
|
3894
|
+
"beast",
|
|
3895
|
+
"savage",
|
|
3896
|
+
"suck",
|
|
3897
|
+
"sucks",
|
|
3898
|
+
"wtf",
|
|
3899
|
+
"omg",
|
|
3900
|
+
"hell",
|
|
3901
|
+
"damn",
|
|
3902
|
+
"crap"
|
|
3903
|
+
]);
|
|
3875
3904
|
var POSITIVE_PHRASES = /* @__PURE__ */ new Map([
|
|
3876
3905
|
["the bomb", 0.9],
|
|
3877
3906
|
// "this movie is the bomb"
|
|
@@ -3904,7 +3933,9 @@ var ContextAnalyzer = class {
|
|
|
3904
3933
|
constructor(config) {
|
|
3905
3934
|
this.contextWindow = config.contextWindow;
|
|
3906
3935
|
this.language = config.language;
|
|
3907
|
-
this.domainWhitelists = new Set(
|
|
3936
|
+
this.domainWhitelists = new Set(
|
|
3937
|
+
(config.domainWhitelists || []).map((word) => word.toLowerCase())
|
|
3938
|
+
);
|
|
3908
3939
|
}
|
|
3909
3940
|
/**
|
|
3910
3941
|
* Analyzes the context around a profanity match to determine if it should be flagged
|
|
@@ -3941,10 +3972,9 @@ var ContextAnalyzer = class {
|
|
|
3941
3972
|
isWhitelisted: false
|
|
3942
3973
|
};
|
|
3943
3974
|
}
|
|
3944
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3945
3975
|
checkPhraseContext(contextText, matchWord) {
|
|
3946
3976
|
for (const [phrase, score] of POSITIVE_PHRASES.entries()) {
|
|
3947
|
-
if (contextText.includes(phrase)) {
|
|
3977
|
+
if (phrase.includes(matchWord) && contextText.includes(phrase)) {
|
|
3948
3978
|
return {
|
|
3949
3979
|
contextScore: score,
|
|
3950
3980
|
reason: `Positive phrase detected: "${phrase}"`,
|
|
@@ -3963,21 +3993,29 @@ var ContextAnalyzer = class {
|
|
|
3963
3993
|
}
|
|
3964
3994
|
return null;
|
|
3965
3995
|
}
|
|
3966
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3967
3996
|
isDomainWhitelisted(contextWords, matchWord) {
|
|
3997
|
+
const normalizedMatchWord = matchWord.toLowerCase();
|
|
3968
3998
|
for (const word of contextWords) {
|
|
3969
|
-
if (this.domainWhitelists.has(word)
|
|
3999
|
+
if (this.domainWhitelists.has(word)) {
|
|
3970
4000
|
return true;
|
|
3971
4001
|
}
|
|
4002
|
+
if (GAMING_POSITIVE.has(word)) {
|
|
4003
|
+
if (GAMING_ACCEPTABLE_WORDS.has(normalizedMatchWord)) {
|
|
4004
|
+
return true;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
3972
4007
|
}
|
|
3973
4008
|
return false;
|
|
3974
4009
|
}
|
|
3975
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3976
4010
|
generateReason(score, contextWords) {
|
|
4011
|
+
const foundPositive = Array.from(new Set(contextWords.filter((word) => POSITIVE_INDICATORS.has(word))));
|
|
4012
|
+
const foundNegative = Array.from(new Set(contextWords.filter((word) => NEGATIVE_INDICATORS.has(word))));
|
|
3977
4013
|
if (score >= 0.7) {
|
|
3978
|
-
|
|
4014
|
+
const details = foundPositive.length > 0 ? ` (found: ${foundPositive.join(", ")})` : "";
|
|
4015
|
+
return `Positive context detected${details} - likely not profanity`;
|
|
3979
4016
|
} else if (score <= 0.3) {
|
|
3980
|
-
|
|
4017
|
+
const details = foundNegative.length > 0 ? ` (found: ${foundNegative.join(", ")})` : "";
|
|
4018
|
+
return `Negative context detected${details} - likely profanity`;
|
|
3981
4019
|
} else {
|
|
3982
4020
|
return "Neutral context - uncertain classification";
|
|
3983
4021
|
}
|
|
@@ -4035,7 +4073,7 @@ var ContextAnalyzer = class {
|
|
|
4035
4073
|
* Updates the domain whitelist for this analyzer instance
|
|
4036
4074
|
*/
|
|
4037
4075
|
updateDomainWhitelist(newWhitelist) {
|
|
4038
|
-
this.domainWhitelists = new Set(newWhitelist);
|
|
4076
|
+
this.domainWhitelists = new Set(newWhitelist.map((word) => word.toLowerCase()));
|
|
4039
4077
|
}
|
|
4040
4078
|
/**
|
|
4041
4079
|
* Adds words to the domain whitelist
|
|
@@ -4235,6 +4273,10 @@ var HOMOGLYPHS = {
|
|
|
4235
4273
|
// Cyrillic small e
|
|
4236
4274
|
"\u0415": "E",
|
|
4237
4275
|
// Cyrillic capital E
|
|
4276
|
+
"\u043A": "k",
|
|
4277
|
+
// Cyrillic small ka
|
|
4278
|
+
"\u041A": "K",
|
|
4279
|
+
// Cyrillic capital Ka
|
|
4238
4280
|
"\u043E": "o",
|
|
4239
4281
|
// Cyrillic small o
|
|
4240
4282
|
"\u041E": "O",
|
|
@@ -4247,9 +4289,9 @@ var HOMOGLYPHS = {
|
|
|
4247
4289
|
// Cyrillic small es
|
|
4248
4290
|
"\u0421": "C",
|
|
4249
4291
|
// Cyrillic capital Es
|
|
4250
|
-
"\u0443": "
|
|
4251
|
-
// Cyrillic small u
|
|
4252
|
-
"\u0423": "
|
|
4292
|
+
"\u0443": "u",
|
|
4293
|
+
// Cyrillic small u (map to u, not y)
|
|
4294
|
+
"\u0423": "U",
|
|
4253
4295
|
// Cyrillic capital U
|
|
4254
4296
|
"\u0445": "x",
|
|
4255
4297
|
// Cyrillic small ha
|
|
@@ -4267,6 +4309,11 @@ var HOMOGLYPHS = {
|
|
|
4267
4309
|
// Cyrillic small dze
|
|
4268
4310
|
"\u0405": "S",
|
|
4269
4311
|
// Cyrillic capital Dze
|
|
4312
|
+
// Currency and special symbols that look like letters
|
|
4313
|
+
"\xA2": "c",
|
|
4314
|
+
// Cent sign
|
|
4315
|
+
"\u0192": "f",
|
|
4316
|
+
// Latin small f with hook (florin)
|
|
4270
4317
|
// Greek homoglyphs
|
|
4271
4318
|
"\u03B1": "a",
|
|
4272
4319
|
// Greek small alpha
|
|
@@ -4638,6 +4685,7 @@ var Filter = class {
|
|
|
4638
4685
|
this.cacheResults = config?.cacheResults ?? false;
|
|
4639
4686
|
this.maxCacheSize = config?.maxCacheSize ?? 1e3;
|
|
4640
4687
|
this.cache = /* @__PURE__ */ new Map();
|
|
4688
|
+
this.regexCache = /* @__PURE__ */ new Map();
|
|
4641
4689
|
let words = [];
|
|
4642
4690
|
if (config?.allLanguages) {
|
|
4643
4691
|
for (const lang in dictionary_default) {
|
|
@@ -4667,9 +4715,10 @@ var Filter = class {
|
|
|
4667
4715
|
* Applies Unicode normalization, leetspeak detection, and obfuscation handling.
|
|
4668
4716
|
*
|
|
4669
4717
|
* @param text - The input text to normalize
|
|
4718
|
+
* @param aggressive - If true, collapses to single chars (for repeated char detection)
|
|
4670
4719
|
* @returns The normalized text
|
|
4671
4720
|
*/
|
|
4672
|
-
normalizeText(text) {
|
|
4721
|
+
normalizeText(text, aggressive = false) {
|
|
4673
4722
|
let normalized = text;
|
|
4674
4723
|
if (this.normalizeUnicodeEnabled) {
|
|
4675
4724
|
normalized = normalizeUnicode(normalized);
|
|
@@ -4678,6 +4727,8 @@ var Filter = class {
|
|
|
4678
4727
|
normalized = normalizeLeetspeak(normalized, {
|
|
4679
4728
|
level: this.leetspeakLevel,
|
|
4680
4729
|
collapseRepeated: true,
|
|
4730
|
+
// Keep double letters like "ss" for normal check, collapse all for aggressive
|
|
4731
|
+
maxRepeated: aggressive ? 1 : 2,
|
|
4681
4732
|
removeSpacedChars: true
|
|
4682
4733
|
});
|
|
4683
4734
|
}
|
|
@@ -4708,6 +4759,7 @@ var Filter = class {
|
|
|
4708
4759
|
*/
|
|
4709
4760
|
clearCache() {
|
|
4710
4761
|
this.cache.clear();
|
|
4762
|
+
this.regexCache.clear();
|
|
4711
4763
|
}
|
|
4712
4764
|
/**
|
|
4713
4765
|
* Gets the current cache size.
|
|
@@ -4789,10 +4841,17 @@ var Filter = class {
|
|
|
4789
4841
|
return this.cache.get(key);
|
|
4790
4842
|
}
|
|
4791
4843
|
getRegex(word) {
|
|
4844
|
+
if (this.regexCache.has(word)) {
|
|
4845
|
+
const regex2 = this.regexCache.get(word);
|
|
4846
|
+
regex2.lastIndex = 0;
|
|
4847
|
+
return regex2;
|
|
4848
|
+
}
|
|
4792
4849
|
const flags = this.caseSensitive ? "g" : "gi";
|
|
4793
4850
|
const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4794
4851
|
const boundary = this.wordBoundaries ? "\\b" : "";
|
|
4795
|
-
|
|
4852
|
+
const regex = new RegExp(`${boundary}${escapedWord}${boundary}`, flags);
|
|
4853
|
+
this.regexCache.set(word, regex);
|
|
4854
|
+
return regex;
|
|
4796
4855
|
}
|
|
4797
4856
|
isFuzzyToleranceMatch(word, text) {
|
|
4798
4857
|
const simplifiedText = text.toLowerCase().replace(/[^a-z]/g, "");
|
|
@@ -4810,11 +4869,12 @@ var Filter = class {
|
|
|
4810
4869
|
return score >= this.fuzzyToleranceLevel;
|
|
4811
4870
|
}
|
|
4812
4871
|
evaluateSeverity(word, text) {
|
|
4813
|
-
if (this.
|
|
4872
|
+
if (this.getRegex(word).test(text)) {
|
|
4814
4873
|
return 1 /* EXACT */;
|
|
4815
4874
|
}
|
|
4816
|
-
if (this.
|
|
4817
|
-
|
|
4875
|
+
if (!this.wordBoundaries && this.isFuzzyToleranceMatch(word, text)) {
|
|
4876
|
+
return 2 /* FUZZY */;
|
|
4877
|
+
}
|
|
4818
4878
|
return void 0;
|
|
4819
4879
|
}
|
|
4820
4880
|
/**
|
|
@@ -4834,9 +4894,20 @@ var Filter = class {
|
|
|
4834
4894
|
* ```
|
|
4835
4895
|
*/
|
|
4836
4896
|
isProfane(value) {
|
|
4837
|
-
const
|
|
4897
|
+
const originalInput = value;
|
|
4898
|
+
const normalizedInput = this.normalizeText(value);
|
|
4899
|
+
const aggressiveInput = this.normalizeText(value, true);
|
|
4838
4900
|
for (const word of this.words.keys()) {
|
|
4839
|
-
if (
|
|
4901
|
+
if (this.ignoreWords.has(word.toLowerCase())) {
|
|
4902
|
+
continue;
|
|
4903
|
+
}
|
|
4904
|
+
if (this.evaluateSeverity(word, originalInput) !== void 0) {
|
|
4905
|
+
return true;
|
|
4906
|
+
}
|
|
4907
|
+
if (this.evaluateSeverity(word, normalizedInput) !== void 0) {
|
|
4908
|
+
return true;
|
|
4909
|
+
}
|
|
4910
|
+
if (this.evaluateSeverity(word, aggressiveInput) !== void 0) {
|
|
4840
4911
|
return true;
|
|
4841
4912
|
}
|
|
4842
4913
|
}
|
|
@@ -4877,23 +4948,45 @@ var Filter = class {
|
|
|
4877
4948
|
return cachedResult;
|
|
4878
4949
|
}
|
|
4879
4950
|
if (!this.enableContextAware) {
|
|
4880
|
-
|
|
4881
|
-
|
|
4951
|
+
const originalInput = text.toLowerCase();
|
|
4952
|
+
const normalizedInput = this.normalizeText(text).toLowerCase();
|
|
4953
|
+
const aggressiveInput = this.normalizeText(text, true).toLowerCase();
|
|
4882
4954
|
const profaneWords2 = [];
|
|
4883
4955
|
const severityMap2 = {};
|
|
4884
4956
|
for (const dictWord of this.words.keys()) {
|
|
4885
4957
|
if (this.ignoreWords.has(dictWord.toLowerCase())) continue;
|
|
4886
|
-
|
|
4958
|
+
let severity = this.evaluateSeverity(dictWord, originalInput);
|
|
4887
4959
|
if (severity !== void 0) {
|
|
4888
4960
|
const regex = this.getRegex(dictWord);
|
|
4889
4961
|
let match;
|
|
4890
|
-
while ((match = regex.exec(
|
|
4962
|
+
while ((match = regex.exec(originalInput)) !== null) {
|
|
4891
4963
|
profaneWords2.push(match[0]);
|
|
4892
4964
|
if (severityMap2[match[0]] === void 0) {
|
|
4893
4965
|
severityMap2[match[0]] = severity;
|
|
4894
4966
|
}
|
|
4895
4967
|
}
|
|
4896
4968
|
}
|
|
4969
|
+
severity = this.evaluateSeverity(dictWord, normalizedInput);
|
|
4970
|
+
if (severity !== void 0) {
|
|
4971
|
+
const regex = this.getRegex(dictWord);
|
|
4972
|
+
while ((regex.exec(normalizedInput)) !== null) {
|
|
4973
|
+
if (!profaneWords2.includes(dictWord)) {
|
|
4974
|
+
profaneWords2.push(dictWord);
|
|
4975
|
+
if (severityMap2[dictWord] === void 0) {
|
|
4976
|
+
severityMap2[dictWord] = severity;
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
severity = this.evaluateSeverity(dictWord, aggressiveInput);
|
|
4982
|
+
if (severity !== void 0) {
|
|
4983
|
+
if (!profaneWords2.includes(dictWord)) {
|
|
4984
|
+
profaneWords2.push(dictWord);
|
|
4985
|
+
if (severityMap2[dictWord] === void 0) {
|
|
4986
|
+
severityMap2[dictWord] = severity;
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4897
4990
|
}
|
|
4898
4991
|
let processedText2 = text;
|
|
4899
4992
|
if (this.replaceWith && profaneWords2.length > 0) {
|
|
@@ -5028,7 +5121,6 @@ var globalWhitelist_default = {
|
|
|
5028
5121
|
"Cucumber",
|
|
5029
5122
|
"Analysis",
|
|
5030
5123
|
"Japan",
|
|
5031
|
-
"Analytics",
|
|
5032
5124
|
"Manipulate",
|
|
5033
5125
|
"Shoot",
|
|
5034
5126
|
"Button",
|
|
@@ -5077,30 +5169,5 @@ async function checkProfanityAsync(text, config) {
|
|
|
5077
5169
|
function isWordProfane(word, config) {
|
|
5078
5170
|
return checkProfanity(word, config).containsProfanity;
|
|
5079
5171
|
}
|
|
5080
|
-
var useProfanityChecker = (config) => {
|
|
5081
|
-
const [result, setResult] = useState(null);
|
|
5082
|
-
const checkText = useCallback((text) => {
|
|
5083
|
-
const checkResult = checkProfanity(text, config);
|
|
5084
|
-
setResult(checkResult);
|
|
5085
|
-
return checkResult;
|
|
5086
|
-
}, [config]);
|
|
5087
|
-
const checkTextAsync = useCallback(async (text) => {
|
|
5088
|
-
const checkResult = await checkProfanityAsync(text, config);
|
|
5089
|
-
setResult(checkResult);
|
|
5090
|
-
return checkResult;
|
|
5091
|
-
}, [config]);
|
|
5092
|
-
const isWordProfaneCallback = useCallback((word) => {
|
|
5093
|
-
return isWordProfane(word, config);
|
|
5094
|
-
}, [config]);
|
|
5095
|
-
const reset = useCallback(() => setResult(null), []);
|
|
5096
|
-
return {
|
|
5097
|
-
result,
|
|
5098
|
-
checkText,
|
|
5099
|
-
checkTextAsync,
|
|
5100
|
-
reset,
|
|
5101
|
-
isDirty: result?.containsProfanity ?? false,
|
|
5102
|
-
isWordProfane: isWordProfaneCallback
|
|
5103
|
-
};
|
|
5104
|
-
};
|
|
5105
5172
|
|
|
5106
|
-
export { Filter, Filter as ProfanityFilter, SeverityLevel, checkProfanity, checkProfanityAsync, collapseRepeatedCharacters, collapseSpacedCharacters, containsLeetspeak, containsUnicodeObfuscation, convertFullWidth, convertHomoglyphs, detectCharacterSets, generateLeetspeakVariants, isWordProfane, normalizeLeetspeak, normalizeNFKD, normalizeUnicode, removeZeroWidthCharacters
|
|
5173
|
+
export { Filter, Filter as ProfanityFilter, SeverityLevel, checkProfanity, checkProfanityAsync, collapseRepeatedCharacters, collapseSpacedCharacters, containsLeetspeak, containsUnicodeObfuscation, convertFullWidth, convertHomoglyphs, detectCharacterSets, generateLeetspeakVariants, isWordProfane, normalizeLeetspeak, normalizeNFKD, normalizeUnicode, removeZeroWidthCharacters };
|