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.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
5
3
|
// ../../shared/dictionaries/arabic.json
|
|
6
4
|
var arabic_default = {
|
|
7
5
|
words: [
|
|
@@ -537,7 +535,7 @@ var danish_default = {
|
|
|
537
535
|
// ../../shared/dictionaries/dutch.json
|
|
538
536
|
var dutch_default = {
|
|
539
537
|
words: [
|
|
540
|
-
"aardappels
|
|
538
|
+
"aardappels afgieten",
|
|
541
539
|
"achter het raam zitten",
|
|
542
540
|
"afberen",
|
|
543
541
|
"aflebberen",
|
|
@@ -554,7 +552,7 @@ var dutch_default = {
|
|
|
554
552
|
"bagger schijten",
|
|
555
553
|
"balen",
|
|
556
554
|
"bedonderen",
|
|
557
|
-
"
|
|
555
|
+
"befborstel",
|
|
558
556
|
"beffen",
|
|
559
557
|
"bekken",
|
|
560
558
|
"belazeren",
|
|
@@ -563,11 +561,11 @@ var dutch_default = {
|
|
|
563
561
|
"beurt",
|
|
564
562
|
"boemelen",
|
|
565
563
|
"boerelul",
|
|
566
|
-
"
|
|
564
|
+
"boerenpummel",
|
|
567
565
|
"bokkelul",
|
|
568
566
|
"botergeil",
|
|
569
567
|
"broekhoesten",
|
|
570
|
-
"
|
|
568
|
+
"brugpieper",
|
|
571
569
|
"buffelen",
|
|
572
570
|
"buiten de pot piesen",
|
|
573
571
|
"da's kloten van de bok",
|
|
@@ -575,13 +573,13 @@ var dutch_default = {
|
|
|
575
573
|
"de hoer spelen",
|
|
576
574
|
"de hond uitlaten",
|
|
577
575
|
"de koffer induiken",
|
|
578
|
-
"
|
|
576
|
+
"del",
|
|
579
577
|
"de pijp aan maarten geven",
|
|
580
578
|
"de pijp uitgaan",
|
|
581
579
|
"dombo",
|
|
582
|
-
"
|
|
580
|
+
"draaikont",
|
|
583
581
|
"driehoog achter wonen",
|
|
584
|
-
"
|
|
582
|
+
"drol",
|
|
585
583
|
"drooggeiler",
|
|
586
584
|
"droogkloot",
|
|
587
585
|
"een beurt geven",
|
|
@@ -601,7 +599,7 @@ var dutch_default = {
|
|
|
601
599
|
"godverdomme",
|
|
602
600
|
"graftak",
|
|
603
601
|
"gras maaien",
|
|
604
|
-
"
|
|
602
|
+
"gratenkut",
|
|
605
603
|
"greppeldel",
|
|
606
604
|
"griet",
|
|
607
605
|
"hoempert",
|
|
@@ -614,7 +612,7 @@ var dutch_default = {
|
|
|
614
612
|
"huisdealer",
|
|
615
613
|
"johny",
|
|
616
614
|
"kanen",
|
|
617
|
-
"
|
|
615
|
+
"kettingzeug",
|
|
618
616
|
"klaarkomen",
|
|
619
617
|
"klerebeer",
|
|
620
618
|
"klojo",
|
|
@@ -624,22 +622,22 @@ var dutch_default = {
|
|
|
624
622
|
"klootzak",
|
|
625
623
|
"kloten",
|
|
626
624
|
"knor",
|
|
627
|
-
"
|
|
625
|
+
"kont",
|
|
628
626
|
"kontneuken",
|
|
629
627
|
"krentekakker",
|
|
630
628
|
"kut",
|
|
631
629
|
"kuttelikkertje",
|
|
632
|
-
"
|
|
630
|
+
"kwakkie",
|
|
633
631
|
"liefdesgrot",
|
|
634
632
|
"lul",
|
|
635
633
|
"lul-de-behanger",
|
|
636
634
|
"lulhannes",
|
|
637
635
|
"lummel",
|
|
638
636
|
"mafketel",
|
|
639
|
-
"
|
|
637
|
+
"matennaaier",
|
|
640
638
|
"matje",
|
|
641
639
|
"mof",
|
|
642
|
-
"
|
|
640
|
+
"muts",
|
|
643
641
|
"naaien",
|
|
644
642
|
"naakt",
|
|
645
643
|
"neuken",
|
|
@@ -659,9 +657,9 @@ var dutch_default = {
|
|
|
659
657
|
"paal",
|
|
660
658
|
"paardelul",
|
|
661
659
|
"palen",
|
|
662
|
-
"
|
|
660
|
+
"penoze",
|
|
663
661
|
"piesen",
|
|
664
|
-
"
|
|
662
|
+
"pijpbekkie",
|
|
665
663
|
"pijpen",
|
|
666
664
|
"pik",
|
|
667
665
|
"pleurislaaier",
|
|
@@ -676,7 +674,7 @@ var dutch_default = {
|
|
|
676
674
|
"reet",
|
|
677
675
|
"reetridder",
|
|
678
676
|
"reet trappen, voor zijn",
|
|
679
|
-
"
|
|
677
|
+
"remsporen",
|
|
680
678
|
"reutelen",
|
|
681
679
|
"rothoer",
|
|
682
680
|
"rotzak",
|
|
@@ -689,25 +687,25 @@ var dutch_default = {
|
|
|
689
687
|
"schuinsmarcheerder",
|
|
690
688
|
"shit",
|
|
691
689
|
"slempen",
|
|
692
|
-
"
|
|
690
|
+
"slet",
|
|
693
691
|
"sletterig",
|
|
694
692
|
"slik mijn zaad",
|
|
695
|
-
"
|
|
693
|
+
"snol",
|
|
696
694
|
"spuiten",
|
|
697
695
|
"standje",
|
|
698
|
-
"standje-
|
|
696
|
+
"standje-69",
|
|
699
697
|
"stoephoer",
|
|
700
698
|
"stootje",
|
|
701
|
-
"
|
|
702
|
-
"
|
|
699
|
+
"stront",
|
|
700
|
+
"sufferd",
|
|
703
701
|
"tapijtnek",
|
|
704
|
-
"
|
|
702
|
+
"teef",
|
|
705
703
|
"temeier",
|
|
706
704
|
"teringlijer",
|
|
707
705
|
"toeter",
|
|
708
|
-
"
|
|
709
|
-
"
|
|
710
|
-
"trottoir
|
|
706
|
+
"tongzoen",
|
|
707
|
+
"triootje",
|
|
708
|
+
"trottoir prostituee",
|
|
711
709
|
"trottoirteef",
|
|
712
710
|
"vergallen",
|
|
713
711
|
"verkloten",
|
|
@@ -780,6 +778,8 @@ var english_default = {
|
|
|
780
778
|
"2 girls 1 cup",
|
|
781
779
|
"2g1c",
|
|
782
780
|
"a$$",
|
|
781
|
+
"@ss",
|
|
782
|
+
"4ss",
|
|
783
783
|
"acrotomophilia",
|
|
784
784
|
"alabama hot pocket",
|
|
785
785
|
"alaskan pipeline",
|
|
@@ -919,6 +919,10 @@ var english_default = {
|
|
|
919
919
|
"eunuch",
|
|
920
920
|
"f*ck",
|
|
921
921
|
"f@ck",
|
|
922
|
+
"f4ck",
|
|
923
|
+
"fvck",
|
|
924
|
+
"phuck",
|
|
925
|
+
"fuk",
|
|
922
926
|
"faggot",
|
|
923
927
|
"fecal",
|
|
924
928
|
"felch",
|
|
@@ -1100,6 +1104,9 @@ var english_default = {
|
|
|
1100
1104
|
"shemale",
|
|
1101
1105
|
"shibari",
|
|
1102
1106
|
"shit",
|
|
1107
|
+
"sh1t",
|
|
1108
|
+
"$hit",
|
|
1109
|
+
"$h!t",
|
|
1103
1110
|
"shitblimp",
|
|
1104
1111
|
"shithead",
|
|
1105
1112
|
"shitshow",
|
|
@@ -2203,7 +2210,7 @@ var italian_default = {
|
|
|
2203
2210
|
"di merda",
|
|
2204
2211
|
"ditalino",
|
|
2205
2212
|
"duro",
|
|
2206
|
-
"fare una
|
|
2213
|
+
"fare una sega",
|
|
2207
2214
|
"fava",
|
|
2208
2215
|
"femminuccia",
|
|
2209
2216
|
"fica",
|
|
@@ -2451,7 +2458,6 @@ var japanese_default = {
|
|
|
2451
2458
|
"\u7389\u8210\u3081",
|
|
2452
2459
|
"\u7DCA\u7E1B",
|
|
2453
2460
|
"\u8FD1\u89AA\u76F8\u59E6",
|
|
2454
|
-
"\u5ACC\u3044",
|
|
2455
2461
|
"\u5F8C\u80CC\u4F4D",
|
|
2456
2462
|
"\u5408\u610F\u306E\u6027\u4EA4",
|
|
2457
2463
|
"\u62F7\u554F",
|
|
@@ -2464,7 +2470,6 @@ var japanese_default = {
|
|
|
2464
2470
|
"\u5C04\u7CBE",
|
|
2465
2471
|
"\u624B\u30B3\u30AD",
|
|
2466
2472
|
"\u7363\u59E6",
|
|
2467
|
-
"\u5973\u306E\u5B50",
|
|
2468
2473
|
"\u5973\u738B\u69D8",
|
|
2469
2474
|
"\u5973\u5B50\u9AD8\u751F",
|
|
2470
2475
|
"\u5973\u88C5",
|
|
@@ -2541,7 +2546,6 @@ var turkish_default = {
|
|
|
2541
2546
|
"ak",
|
|
2542
2547
|
"akp",
|
|
2543
2548
|
"al a\u011Fz\u0131na",
|
|
2544
|
-
"allah",
|
|
2545
2549
|
"allahs\u0131z",
|
|
2546
2550
|
"am",
|
|
2547
2551
|
"am biti",
|
|
@@ -2636,7 +2640,6 @@ var turkish_default = {
|
|
|
2636
2640
|
"am\u0131n\u0131 s",
|
|
2637
2641
|
"am\u0131s\u0131na",
|
|
2638
2642
|
"am\u0131s\u0131n\u0131",
|
|
2639
|
-
"ana",
|
|
2640
2643
|
"anaaann",
|
|
2641
2644
|
"anal",
|
|
2642
2645
|
"analarn",
|
|
@@ -2768,8 +2771,6 @@ var turkish_default = {
|
|
|
2768
2771
|
"cikar",
|
|
2769
2772
|
"cim",
|
|
2770
2773
|
"cm",
|
|
2771
|
-
"coca cola",
|
|
2772
|
-
"cola",
|
|
2773
2774
|
"dalaks\u0131z",
|
|
2774
2775
|
"dallama",
|
|
2775
2776
|
"daltassak",
|
|
@@ -3567,7 +3568,7 @@ var turkish_default = {
|
|
|
3567
3568
|
// ../../shared/dictionaries/spanish.json
|
|
3568
3569
|
var spanish_default = {
|
|
3569
3570
|
words: [
|
|
3570
|
-
"
|
|
3571
|
+
"asesinato",
|
|
3571
3572
|
"asno",
|
|
3572
3573
|
"bastardo",
|
|
3573
3574
|
"Bollera",
|
|
@@ -3874,6 +3875,34 @@ var GAMING_POSITIVE = /* @__PURE__ */ new Set([
|
|
|
3874
3875
|
"move",
|
|
3875
3876
|
"combo"
|
|
3876
3877
|
]);
|
|
3878
|
+
var GAMING_ACCEPTABLE_WORDS = /* @__PURE__ */ new Set([
|
|
3879
|
+
"kill",
|
|
3880
|
+
"killer",
|
|
3881
|
+
"killed",
|
|
3882
|
+
"killing",
|
|
3883
|
+
"shoot",
|
|
3884
|
+
"shot",
|
|
3885
|
+
"shooting",
|
|
3886
|
+
"die",
|
|
3887
|
+
"dying",
|
|
3888
|
+
"died",
|
|
3889
|
+
"dead",
|
|
3890
|
+
"death",
|
|
3891
|
+
"badass",
|
|
3892
|
+
"sick",
|
|
3893
|
+
"insane",
|
|
3894
|
+
"crazy",
|
|
3895
|
+
"mad",
|
|
3896
|
+
"beast",
|
|
3897
|
+
"savage",
|
|
3898
|
+
"suck",
|
|
3899
|
+
"sucks",
|
|
3900
|
+
"wtf",
|
|
3901
|
+
"omg",
|
|
3902
|
+
"hell",
|
|
3903
|
+
"damn",
|
|
3904
|
+
"crap"
|
|
3905
|
+
]);
|
|
3877
3906
|
var POSITIVE_PHRASES = /* @__PURE__ */ new Map([
|
|
3878
3907
|
["the bomb", 0.9],
|
|
3879
3908
|
// "this movie is the bomb"
|
|
@@ -3906,7 +3935,9 @@ var ContextAnalyzer = class {
|
|
|
3906
3935
|
constructor(config) {
|
|
3907
3936
|
this.contextWindow = config.contextWindow;
|
|
3908
3937
|
this.language = config.language;
|
|
3909
|
-
this.domainWhitelists = new Set(
|
|
3938
|
+
this.domainWhitelists = new Set(
|
|
3939
|
+
(config.domainWhitelists || []).map((word) => word.toLowerCase())
|
|
3940
|
+
);
|
|
3910
3941
|
}
|
|
3911
3942
|
/**
|
|
3912
3943
|
* Analyzes the context around a profanity match to determine if it should be flagged
|
|
@@ -3943,10 +3974,9 @@ var ContextAnalyzer = class {
|
|
|
3943
3974
|
isWhitelisted: false
|
|
3944
3975
|
};
|
|
3945
3976
|
}
|
|
3946
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3947
3977
|
checkPhraseContext(contextText, matchWord) {
|
|
3948
3978
|
for (const [phrase, score] of POSITIVE_PHRASES.entries()) {
|
|
3949
|
-
if (contextText.includes(phrase)) {
|
|
3979
|
+
if (phrase.includes(matchWord) && contextText.includes(phrase)) {
|
|
3950
3980
|
return {
|
|
3951
3981
|
contextScore: score,
|
|
3952
3982
|
reason: `Positive phrase detected: "${phrase}"`,
|
|
@@ -3965,21 +3995,29 @@ var ContextAnalyzer = class {
|
|
|
3965
3995
|
}
|
|
3966
3996
|
return null;
|
|
3967
3997
|
}
|
|
3968
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3969
3998
|
isDomainWhitelisted(contextWords, matchWord) {
|
|
3999
|
+
const normalizedMatchWord = matchWord.toLowerCase();
|
|
3970
4000
|
for (const word of contextWords) {
|
|
3971
|
-
if (this.domainWhitelists.has(word)
|
|
4001
|
+
if (this.domainWhitelists.has(word)) {
|
|
3972
4002
|
return true;
|
|
3973
4003
|
}
|
|
4004
|
+
if (GAMING_POSITIVE.has(word)) {
|
|
4005
|
+
if (GAMING_ACCEPTABLE_WORDS.has(normalizedMatchWord)) {
|
|
4006
|
+
return true;
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
3974
4009
|
}
|
|
3975
4010
|
return false;
|
|
3976
4011
|
}
|
|
3977
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3978
4012
|
generateReason(score, contextWords) {
|
|
4013
|
+
const foundPositive = Array.from(new Set(contextWords.filter((word) => POSITIVE_INDICATORS.has(word))));
|
|
4014
|
+
const foundNegative = Array.from(new Set(contextWords.filter((word) => NEGATIVE_INDICATORS.has(word))));
|
|
3979
4015
|
if (score >= 0.7) {
|
|
3980
|
-
|
|
4016
|
+
const details = foundPositive.length > 0 ? ` (found: ${foundPositive.join(", ")})` : "";
|
|
4017
|
+
return `Positive context detected${details} - likely not profanity`;
|
|
3981
4018
|
} else if (score <= 0.3) {
|
|
3982
|
-
|
|
4019
|
+
const details = foundNegative.length > 0 ? ` (found: ${foundNegative.join(", ")})` : "";
|
|
4020
|
+
return `Negative context detected${details} - likely profanity`;
|
|
3983
4021
|
} else {
|
|
3984
4022
|
return "Neutral context - uncertain classification";
|
|
3985
4023
|
}
|
|
@@ -4037,7 +4075,7 @@ var ContextAnalyzer = class {
|
|
|
4037
4075
|
* Updates the domain whitelist for this analyzer instance
|
|
4038
4076
|
*/
|
|
4039
4077
|
updateDomainWhitelist(newWhitelist) {
|
|
4040
|
-
this.domainWhitelists = new Set(newWhitelist);
|
|
4078
|
+
this.domainWhitelists = new Set(newWhitelist.map((word) => word.toLowerCase()));
|
|
4041
4079
|
}
|
|
4042
4080
|
/**
|
|
4043
4081
|
* Adds words to the domain whitelist
|
|
@@ -4237,6 +4275,10 @@ var HOMOGLYPHS = {
|
|
|
4237
4275
|
// Cyrillic small e
|
|
4238
4276
|
"\u0415": "E",
|
|
4239
4277
|
// Cyrillic capital E
|
|
4278
|
+
"\u043A": "k",
|
|
4279
|
+
// Cyrillic small ka
|
|
4280
|
+
"\u041A": "K",
|
|
4281
|
+
// Cyrillic capital Ka
|
|
4240
4282
|
"\u043E": "o",
|
|
4241
4283
|
// Cyrillic small o
|
|
4242
4284
|
"\u041E": "O",
|
|
@@ -4249,9 +4291,9 @@ var HOMOGLYPHS = {
|
|
|
4249
4291
|
// Cyrillic small es
|
|
4250
4292
|
"\u0421": "C",
|
|
4251
4293
|
// Cyrillic capital Es
|
|
4252
|
-
"\u0443": "
|
|
4253
|
-
// Cyrillic small u
|
|
4254
|
-
"\u0423": "
|
|
4294
|
+
"\u0443": "u",
|
|
4295
|
+
// Cyrillic small u (map to u, not y)
|
|
4296
|
+
"\u0423": "U",
|
|
4255
4297
|
// Cyrillic capital U
|
|
4256
4298
|
"\u0445": "x",
|
|
4257
4299
|
// Cyrillic small ha
|
|
@@ -4269,6 +4311,11 @@ var HOMOGLYPHS = {
|
|
|
4269
4311
|
// Cyrillic small dze
|
|
4270
4312
|
"\u0405": "S",
|
|
4271
4313
|
// Cyrillic capital Dze
|
|
4314
|
+
// Currency and special symbols that look like letters
|
|
4315
|
+
"\xA2": "c",
|
|
4316
|
+
// Cent sign
|
|
4317
|
+
"\u0192": "f",
|
|
4318
|
+
// Latin small f with hook (florin)
|
|
4272
4319
|
// Greek homoglyphs
|
|
4273
4320
|
"\u03B1": "a",
|
|
4274
4321
|
// Greek small alpha
|
|
@@ -4640,6 +4687,7 @@ var Filter = class {
|
|
|
4640
4687
|
this.cacheResults = config?.cacheResults ?? false;
|
|
4641
4688
|
this.maxCacheSize = config?.maxCacheSize ?? 1e3;
|
|
4642
4689
|
this.cache = /* @__PURE__ */ new Map();
|
|
4690
|
+
this.regexCache = /* @__PURE__ */ new Map();
|
|
4643
4691
|
let words = [];
|
|
4644
4692
|
if (config?.allLanguages) {
|
|
4645
4693
|
for (const lang in dictionary_default) {
|
|
@@ -4669,9 +4717,10 @@ var Filter = class {
|
|
|
4669
4717
|
* Applies Unicode normalization, leetspeak detection, and obfuscation handling.
|
|
4670
4718
|
*
|
|
4671
4719
|
* @param text - The input text to normalize
|
|
4720
|
+
* @param aggressive - If true, collapses to single chars (for repeated char detection)
|
|
4672
4721
|
* @returns The normalized text
|
|
4673
4722
|
*/
|
|
4674
|
-
normalizeText(text) {
|
|
4723
|
+
normalizeText(text, aggressive = false) {
|
|
4675
4724
|
let normalized = text;
|
|
4676
4725
|
if (this.normalizeUnicodeEnabled) {
|
|
4677
4726
|
normalized = normalizeUnicode(normalized);
|
|
@@ -4680,6 +4729,8 @@ var Filter = class {
|
|
|
4680
4729
|
normalized = normalizeLeetspeak(normalized, {
|
|
4681
4730
|
level: this.leetspeakLevel,
|
|
4682
4731
|
collapseRepeated: true,
|
|
4732
|
+
// Keep double letters like "ss" for normal check, collapse all for aggressive
|
|
4733
|
+
maxRepeated: aggressive ? 1 : 2,
|
|
4683
4734
|
removeSpacedChars: true
|
|
4684
4735
|
});
|
|
4685
4736
|
}
|
|
@@ -4710,6 +4761,7 @@ var Filter = class {
|
|
|
4710
4761
|
*/
|
|
4711
4762
|
clearCache() {
|
|
4712
4763
|
this.cache.clear();
|
|
4764
|
+
this.regexCache.clear();
|
|
4713
4765
|
}
|
|
4714
4766
|
/**
|
|
4715
4767
|
* Gets the current cache size.
|
|
@@ -4791,10 +4843,17 @@ var Filter = class {
|
|
|
4791
4843
|
return this.cache.get(key);
|
|
4792
4844
|
}
|
|
4793
4845
|
getRegex(word) {
|
|
4846
|
+
if (this.regexCache.has(word)) {
|
|
4847
|
+
const regex2 = this.regexCache.get(word);
|
|
4848
|
+
regex2.lastIndex = 0;
|
|
4849
|
+
return regex2;
|
|
4850
|
+
}
|
|
4794
4851
|
const flags = this.caseSensitive ? "g" : "gi";
|
|
4795
4852
|
const escapedWord = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4796
4853
|
const boundary = this.wordBoundaries ? "\\b" : "";
|
|
4797
|
-
|
|
4854
|
+
const regex = new RegExp(`${boundary}${escapedWord}${boundary}`, flags);
|
|
4855
|
+
this.regexCache.set(word, regex);
|
|
4856
|
+
return regex;
|
|
4798
4857
|
}
|
|
4799
4858
|
isFuzzyToleranceMatch(word, text) {
|
|
4800
4859
|
const simplifiedText = text.toLowerCase().replace(/[^a-z]/g, "");
|
|
@@ -4812,11 +4871,12 @@ var Filter = class {
|
|
|
4812
4871
|
return score >= this.fuzzyToleranceLevel;
|
|
4813
4872
|
}
|
|
4814
4873
|
evaluateSeverity(word, text) {
|
|
4815
|
-
if (this.
|
|
4874
|
+
if (this.getRegex(word).test(text)) {
|
|
4816
4875
|
return 1 /* EXACT */;
|
|
4817
4876
|
}
|
|
4818
|
-
if (this.
|
|
4819
|
-
|
|
4877
|
+
if (!this.wordBoundaries && this.isFuzzyToleranceMatch(word, text)) {
|
|
4878
|
+
return 2 /* FUZZY */;
|
|
4879
|
+
}
|
|
4820
4880
|
return void 0;
|
|
4821
4881
|
}
|
|
4822
4882
|
/**
|
|
@@ -4836,9 +4896,20 @@ var Filter = class {
|
|
|
4836
4896
|
* ```
|
|
4837
4897
|
*/
|
|
4838
4898
|
isProfane(value) {
|
|
4839
|
-
const
|
|
4899
|
+
const originalInput = value;
|
|
4900
|
+
const normalizedInput = this.normalizeText(value);
|
|
4901
|
+
const aggressiveInput = this.normalizeText(value, true);
|
|
4840
4902
|
for (const word of this.words.keys()) {
|
|
4841
|
-
if (
|
|
4903
|
+
if (this.ignoreWords.has(word.toLowerCase())) {
|
|
4904
|
+
continue;
|
|
4905
|
+
}
|
|
4906
|
+
if (this.evaluateSeverity(word, originalInput) !== void 0) {
|
|
4907
|
+
return true;
|
|
4908
|
+
}
|
|
4909
|
+
if (this.evaluateSeverity(word, normalizedInput) !== void 0) {
|
|
4910
|
+
return true;
|
|
4911
|
+
}
|
|
4912
|
+
if (this.evaluateSeverity(word, aggressiveInput) !== void 0) {
|
|
4842
4913
|
return true;
|
|
4843
4914
|
}
|
|
4844
4915
|
}
|
|
@@ -4879,23 +4950,45 @@ var Filter = class {
|
|
|
4879
4950
|
return cachedResult;
|
|
4880
4951
|
}
|
|
4881
4952
|
if (!this.enableContextAware) {
|
|
4882
|
-
|
|
4883
|
-
|
|
4953
|
+
const originalInput = text.toLowerCase();
|
|
4954
|
+
const normalizedInput = this.normalizeText(text).toLowerCase();
|
|
4955
|
+
const aggressiveInput = this.normalizeText(text, true).toLowerCase();
|
|
4884
4956
|
const profaneWords2 = [];
|
|
4885
4957
|
const severityMap2 = {};
|
|
4886
4958
|
for (const dictWord of this.words.keys()) {
|
|
4887
4959
|
if (this.ignoreWords.has(dictWord.toLowerCase())) continue;
|
|
4888
|
-
|
|
4960
|
+
let severity = this.evaluateSeverity(dictWord, originalInput);
|
|
4889
4961
|
if (severity !== void 0) {
|
|
4890
4962
|
const regex = this.getRegex(dictWord);
|
|
4891
4963
|
let match;
|
|
4892
|
-
while ((match = regex.exec(
|
|
4964
|
+
while ((match = regex.exec(originalInput)) !== null) {
|
|
4893
4965
|
profaneWords2.push(match[0]);
|
|
4894
4966
|
if (severityMap2[match[0]] === void 0) {
|
|
4895
4967
|
severityMap2[match[0]] = severity;
|
|
4896
4968
|
}
|
|
4897
4969
|
}
|
|
4898
4970
|
}
|
|
4971
|
+
severity = this.evaluateSeverity(dictWord, normalizedInput);
|
|
4972
|
+
if (severity !== void 0) {
|
|
4973
|
+
const regex = this.getRegex(dictWord);
|
|
4974
|
+
while ((regex.exec(normalizedInput)) !== null) {
|
|
4975
|
+
if (!profaneWords2.includes(dictWord)) {
|
|
4976
|
+
profaneWords2.push(dictWord);
|
|
4977
|
+
if (severityMap2[dictWord] === void 0) {
|
|
4978
|
+
severityMap2[dictWord] = severity;
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
severity = this.evaluateSeverity(dictWord, aggressiveInput);
|
|
4984
|
+
if (severity !== void 0) {
|
|
4985
|
+
if (!profaneWords2.includes(dictWord)) {
|
|
4986
|
+
profaneWords2.push(dictWord);
|
|
4987
|
+
if (severityMap2[dictWord] === void 0) {
|
|
4988
|
+
severityMap2[dictWord] = severity;
|
|
4989
|
+
}
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4899
4992
|
}
|
|
4900
4993
|
let processedText2 = text;
|
|
4901
4994
|
if (this.replaceWith && profaneWords2.length > 0) {
|
|
@@ -5030,7 +5123,6 @@ var globalWhitelist_default = {
|
|
|
5030
5123
|
"Cucumber",
|
|
5031
5124
|
"Analysis",
|
|
5032
5125
|
"Japan",
|
|
5033
|
-
"Analytics",
|
|
5034
5126
|
"Manipulate",
|
|
5035
5127
|
"Shoot",
|
|
5036
5128
|
"Button",
|
|
@@ -5079,31 +5171,6 @@ async function checkProfanityAsync(text, config) {
|
|
|
5079
5171
|
function isWordProfane(word, config) {
|
|
5080
5172
|
return checkProfanity(word, config).containsProfanity;
|
|
5081
5173
|
}
|
|
5082
|
-
var useProfanityChecker = (config) => {
|
|
5083
|
-
const [result, setResult] = react.useState(null);
|
|
5084
|
-
const checkText = react.useCallback((text) => {
|
|
5085
|
-
const checkResult = checkProfanity(text, config);
|
|
5086
|
-
setResult(checkResult);
|
|
5087
|
-
return checkResult;
|
|
5088
|
-
}, [config]);
|
|
5089
|
-
const checkTextAsync = react.useCallback(async (text) => {
|
|
5090
|
-
const checkResult = await checkProfanityAsync(text, config);
|
|
5091
|
-
setResult(checkResult);
|
|
5092
|
-
return checkResult;
|
|
5093
|
-
}, [config]);
|
|
5094
|
-
const isWordProfaneCallback = react.useCallback((word) => {
|
|
5095
|
-
return isWordProfane(word, config);
|
|
5096
|
-
}, [config]);
|
|
5097
|
-
const reset = react.useCallback(() => setResult(null), []);
|
|
5098
|
-
return {
|
|
5099
|
-
result,
|
|
5100
|
-
checkText,
|
|
5101
|
-
checkTextAsync,
|
|
5102
|
-
reset,
|
|
5103
|
-
isDirty: result?.containsProfanity ?? false,
|
|
5104
|
-
isWordProfane: isWordProfaneCallback
|
|
5105
|
-
};
|
|
5106
|
-
};
|
|
5107
5174
|
|
|
5108
5175
|
exports.Filter = Filter;
|
|
5109
5176
|
exports.ProfanityFilter = Filter;
|
|
@@ -5123,4 +5190,3 @@ exports.normalizeLeetspeak = normalizeLeetspeak;
|
|
|
5123
5190
|
exports.normalizeNFKD = normalizeNFKD;
|
|
5124
5191
|
exports.normalizeUnicode = normalizeUnicode;
|
|
5125
5192
|
exports.removeZeroWidthCharacters = removeZeroWidthCharacters;
|
|
5126
|
-
exports.useProfanityChecker = useProfanityChecker;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Configuration options for the profanity checker hook and functions.
|
|
6
|
-
* Extends FilterConfig with additional convenience options for V3 features.
|
|
7
|
-
*/
|
|
8
|
-
interface ProfanityCheckerConfig extends Omit<FilterConfig, 'logProfanity'> {
|
|
9
|
-
/** Minimum severity level to include in results */
|
|
10
|
-
minSeverity?: SeverityLevel;
|
|
11
|
-
/** Auto-replace profanity with replaceWith string */
|
|
12
|
-
autoReplace?: boolean;
|
|
13
|
-
/** Custom callback when profanity is detected */
|
|
14
|
-
customActions?: (result: CheckProfanityResult) => void;
|
|
15
|
-
}
|
|
16
|
-
interface ProfanityCheckResult extends CheckProfanityResult {
|
|
17
|
-
filteredWords: string[];
|
|
18
|
-
autoReplaced: string;
|
|
19
|
-
}
|
|
1
|
+
import { P as ProfanityCheckerConfig, a as ProfanityCheckResult } from './types-DI8nzwWc.cjs';
|
|
2
|
+
export { F as Filter, F as ProfanityFilter } from './Filter-D34Wsmrj.cjs';
|
|
3
|
+
export { C as CheckProfanityResult, b as ContextAwareConfig, F as FilterConfig, a as FilteredProfanityResult, L as Language, M as Match, S as SeverityLevel } from './types-B9c_ik4k.cjs';
|
|
4
|
+
export { H as HybridAnalysisResult, a as MLAnalysisResult, M as MLDetectorConfig, T as ToxicityLabel, b as ToxicityPrediction } from './types-Ct_ueYqw.cjs';
|
|
20
5
|
|
|
21
6
|
declare function checkProfanity(text: string, config?: ProfanityCheckerConfig): ProfanityCheckResult;
|
|
22
7
|
declare function checkProfanityAsync(text: string, config?: ProfanityCheckerConfig): Promise<ProfanityCheckResult>;
|
|
23
8
|
declare function isWordProfane(word: string, config?: ProfanityCheckerConfig): boolean;
|
|
24
9
|
|
|
25
|
-
declare const useProfanityChecker: (config?: ProfanityCheckerConfig) => {
|
|
26
|
-
result: CheckProfanityResult;
|
|
27
|
-
checkText: (text: string) => ProfanityCheckResult;
|
|
28
|
-
checkTextAsync: (text: string) => Promise<ProfanityCheckResult>;
|
|
29
|
-
reset: () => void;
|
|
30
|
-
isDirty: boolean;
|
|
31
|
-
isWordProfane: (word: string) => boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
10
|
/**
|
|
35
11
|
* @fileoverview Leetspeak detection and normalization utilities.
|
|
36
12
|
* Converts leetspeak/1337 speak text back to standard characters for profanity detection.
|
|
@@ -279,4 +255,4 @@ declare function detectCharacterSets(text: string): {
|
|
|
279
255
|
hasMixed: boolean;
|
|
280
256
|
};
|
|
281
257
|
|
|
282
|
-
export {
|
|
258
|
+
export { type LeetspeakLevel, type LeetspeakOptions, ProfanityCheckResult, ProfanityCheckerConfig, type UnicodeNormalizationOptions, checkProfanity, checkProfanityAsync, collapseRepeatedCharacters, collapseSpacedCharacters, containsLeetspeak, containsUnicodeObfuscation, convertFullWidth, convertHomoglyphs, detectCharacterSets, generateLeetspeakVariants, isWordProfane, normalizeLeetspeak, normalizeNFKD, normalizeUnicode, removeZeroWidthCharacters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Configuration options for the profanity checker hook and functions.
|
|
6
|
-
* Extends FilterConfig with additional convenience options for V3 features.
|
|
7
|
-
*/
|
|
8
|
-
interface ProfanityCheckerConfig extends Omit<FilterConfig, 'logProfanity'> {
|
|
9
|
-
/** Minimum severity level to include in results */
|
|
10
|
-
minSeverity?: SeverityLevel;
|
|
11
|
-
/** Auto-replace profanity with replaceWith string */
|
|
12
|
-
autoReplace?: boolean;
|
|
13
|
-
/** Custom callback when profanity is detected */
|
|
14
|
-
customActions?: (result: CheckProfanityResult) => void;
|
|
15
|
-
}
|
|
16
|
-
interface ProfanityCheckResult extends CheckProfanityResult {
|
|
17
|
-
filteredWords: string[];
|
|
18
|
-
autoReplaced: string;
|
|
19
|
-
}
|
|
1
|
+
import { P as ProfanityCheckerConfig, a as ProfanityCheckResult } from './types-BuKh9tvV.js';
|
|
2
|
+
export { F as Filter, F as ProfanityFilter } from './Filter-BGcyIAvO.js';
|
|
3
|
+
export { C as CheckProfanityResult, b as ContextAwareConfig, F as FilterConfig, a as FilteredProfanityResult, L as Language, M as Match, S as SeverityLevel } from './types-B9c_ik4k.js';
|
|
4
|
+
export { H as HybridAnalysisResult, a as MLAnalysisResult, M as MLDetectorConfig, T as ToxicityLabel, b as ToxicityPrediction } from './types-Ct_ueYqw.js';
|
|
20
5
|
|
|
21
6
|
declare function checkProfanity(text: string, config?: ProfanityCheckerConfig): ProfanityCheckResult;
|
|
22
7
|
declare function checkProfanityAsync(text: string, config?: ProfanityCheckerConfig): Promise<ProfanityCheckResult>;
|
|
23
8
|
declare function isWordProfane(word: string, config?: ProfanityCheckerConfig): boolean;
|
|
24
9
|
|
|
25
|
-
declare const useProfanityChecker: (config?: ProfanityCheckerConfig) => {
|
|
26
|
-
result: CheckProfanityResult;
|
|
27
|
-
checkText: (text: string) => ProfanityCheckResult;
|
|
28
|
-
checkTextAsync: (text: string) => Promise<ProfanityCheckResult>;
|
|
29
|
-
reset: () => void;
|
|
30
|
-
isDirty: boolean;
|
|
31
|
-
isWordProfane: (word: string) => boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
10
|
/**
|
|
35
11
|
* @fileoverview Leetspeak detection and normalization utilities.
|
|
36
12
|
* Converts leetspeak/1337 speak text back to standard characters for profanity detection.
|
|
@@ -279,4 +255,4 @@ declare function detectCharacterSets(text: string): {
|
|
|
279
255
|
hasMixed: boolean;
|
|
280
256
|
};
|
|
281
257
|
|
|
282
|
-
export {
|
|
258
|
+
export { type LeetspeakLevel, type LeetspeakOptions, ProfanityCheckResult, ProfanityCheckerConfig, type UnicodeNormalizationOptions, checkProfanity, checkProfanityAsync, collapseRepeatedCharacters, collapseSpacedCharacters, containsLeetspeak, containsUnicodeObfuscation, convertFullWidth, convertHomoglyphs, detectCharacterSets, generateLeetspeakVariants, isWordProfane, normalizeLeetspeak, normalizeNFKD, normalizeUnicode, removeZeroWidthCharacters };
|