@sideid/id-profanity-filter 1.11.7 → 1.11.9

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.
Files changed (53) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.esm.js +1166 -438
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +1166 -438
  5. package/dist/index.js.map +1 -1
  6. package/dist/types/config/options.d.ts +1 -1
  7. package/dist/types/constants/categories/blasphemy.d.ts +1 -1
  8. package/dist/types/constants/categories/disgusting.d.ts +1 -1
  9. package/dist/types/constants/categories/drugs.d.ts +1 -1
  10. package/dist/types/constants/categories/insult.d.ts +1 -1
  11. package/dist/types/constants/categories/profanity.d.ts +1 -1
  12. package/dist/types/constants/categories/sexual.d.ts +1 -1
  13. package/dist/types/constants/categories/slur.d.ts +1 -1
  14. package/dist/types/constants/regions/bali.d.ts +1 -1
  15. package/dist/types/constants/regions/batak.d.ts +1 -1
  16. package/dist/types/constants/regions/betawi.d.ts +1 -1
  17. package/dist/types/constants/regions/general.d.ts +1 -1
  18. package/dist/types/constants/regions/minang.d.ts +4 -0
  19. package/dist/types/constants/wordList.d.ts +10 -1
  20. package/dist/types/core/analyzer.d.ts +1 -1
  21. package/dist/types/core/filter.d.ts +1 -1
  22. package/dist/types/core/matcher.d.ts +1 -1
  23. package/dist/types/types/index.d.ts +2 -2
  24. package/dist/types/utils/regexUtils.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/src/config/options.ts +25 -30
  27. package/src/constants/categories/blasphemy.ts +26 -15
  28. package/src/constants/categories/disgusting.ts +62 -54
  29. package/src/constants/categories/drugs.ts +56 -47
  30. package/src/constants/categories/insult.ts +80 -76
  31. package/src/constants/categories/profanity.ts +98 -92
  32. package/src/constants/categories/sexual.ts +74 -65
  33. package/src/constants/categories/slur.ts +73 -66
  34. package/src/constants/regions/aceh.ts +5 -9
  35. package/src/constants/regions/bali.ts +4 -7
  36. package/src/constants/regions/batak.ts +169 -9
  37. package/src/constants/regions/betawi.ts +19 -22
  38. package/src/constants/regions/general.ts +140 -144
  39. package/src/constants/regions/jawa.ts +11 -29
  40. package/src/constants/regions/madura.ts +2 -4
  41. package/src/constants/regions/minang.ts +53 -0
  42. package/src/constants/regions/sunda.ts +2 -4
  43. package/src/constants/wordList.ts +31 -34
  44. package/src/core/analyzer.ts +15 -26
  45. package/src/core/filter.ts +23 -39
  46. package/src/core/matcher.ts +25 -49
  47. package/src/index.ts +5 -16
  48. package/src/types/index.ts +26 -25
  49. package/src/utils/ahoCorasick.ts +1 -1
  50. package/src/utils/regexUtils.ts +37 -43
  51. package/src/utils/similarityUtils.ts +13 -28
  52. package/src/utils/stringUtils.ts +30 -38
  53. /package/{prettierrc → .prettierrc} +0 -0
@@ -1,7 +1,7 @@
1
- import { FilterOptions, ProfanityCategory, Region } from "../types";
1
+ import { FilterOptions, ProfanityCategory, Region } from '../types';
2
2
 
3
3
  export const DEFAULT_OPTIONS: FilterOptions = {
4
- replaceWith: "*",
4
+ replaceWith: '*',
5
5
  fullWordCensor: true,
6
6
  detectLeetSpeak: true,
7
7
  checkSubstring: false,
@@ -27,7 +27,7 @@ export const FILTER_PRESETS = {
27
27
  light: {
28
28
  ...DEFAULT_OPTIONS,
29
29
  severityThreshold: 0.7,
30
- categories: ["sexual", "slur", "blasphemy"] as ProfanityCategory[],
30
+ categories: ['sexual', 'slur', 'blasphemy'] as ProfanityCategory[],
31
31
  },
32
32
 
33
33
  childSafe: {
@@ -42,57 +42,57 @@ export const FILTER_PRESETS = {
42
42
  export const CATEGORY_PRESETS = {
43
43
  sexual: {
44
44
  ...DEFAULT_OPTIONS,
45
- categories: ["sexual"] as ProfanityCategory[],
45
+ categories: ['sexual'] as ProfanityCategory[],
46
46
  },
47
47
 
48
48
  insults: {
49
49
  ...DEFAULT_OPTIONS,
50
- categories: ["insult"] as ProfanityCategory[],
50
+ categories: ['insult'] as ProfanityCategory[],
51
51
  },
52
52
 
53
53
  profanity: {
54
54
  ...DEFAULT_OPTIONS,
55
- categories: ["profanity"] as ProfanityCategory[],
55
+ categories: ['profanity'] as ProfanityCategory[],
56
56
  },
57
57
  };
58
58
 
59
59
  export const REGION_PRESETS = {
60
60
  general: {
61
61
  ...DEFAULT_OPTIONS,
62
- regions: ["general"] as Region[],
62
+ regions: ['general'] as Region[],
63
63
  },
64
64
 
65
65
  jawa: {
66
66
  ...DEFAULT_OPTIONS,
67
- regions: ["jawa"] as Region[],
67
+ regions: ['jawa'] as Region[],
68
68
  },
69
69
 
70
70
  sunda: {
71
71
  ...DEFAULT_OPTIONS,
72
- regions: ["sunda"] as Region[],
72
+ regions: ['sunda'] as Region[],
73
73
  },
74
74
 
75
75
  betawi: {
76
76
  ...DEFAULT_OPTIONS,
77
- regions: ["betawi"] as Region[],
77
+ regions: ['betawi'] as Region[],
78
78
  },
79
79
 
80
80
  batak: {
81
81
  ...DEFAULT_OPTIONS,
82
- regions: ["batak"] as Region[],
82
+ regions: ['batak'] as Region[],
83
83
  },
84
84
  };
85
85
 
86
86
  export const REPLACEMENT_CHARS = {
87
- asterisk: "*",
88
- hash: "#",
89
- dollar: "$",
90
- at: "@",
91
- percent: "%",
92
- underscore: "_",
93
- dash: "-",
94
- dot: ".",
95
- grawlix: "#@$%&!",
87
+ asterisk: '*',
88
+ hash: '#',
89
+ dollar: '$',
90
+ at: '@',
91
+ percent: '%',
92
+ underscore: '_',
93
+ dash: '-',
94
+ dot: '.',
95
+ grawlix: '#@$%&!',
96
96
  };
97
97
 
98
98
  /**
@@ -101,9 +101,7 @@ export const REPLACEMENT_CHARS = {
101
101
  * @param options Opsi yang akan digabungkan dengan default
102
102
  * @returns Opsi yang sudah digabungkan
103
103
  */
104
- export function createOptions(
105
- options: Partial<FilterOptions> = {},
106
- ): FilterOptions {
104
+ export function createOptions(options: Partial<FilterOptions> = {}): FilterOptions {
107
105
  return {
108
106
  ...DEFAULT_OPTIONS,
109
107
  ...options,
@@ -119,15 +117,14 @@ export function createOptions(
119
117
  */
120
118
  export function getPresetOptions(
121
119
  presetName: string,
122
- additionalOptions: Partial<FilterOptions> = {},
120
+ additionalOptions: Partial<FilterOptions> = {}
123
121
  ): FilterOptions {
124
122
  let presetOptions: FilterOptions;
125
123
 
126
124
  if (presetName in FILTER_PRESETS) {
127
125
  presetOptions = FILTER_PRESETS[presetName as keyof typeof FILTER_PRESETS];
128
126
  } else if (presetName in CATEGORY_PRESETS) {
129
- presetOptions =
130
- CATEGORY_PRESETS[presetName as keyof typeof CATEGORY_PRESETS];
127
+ presetOptions = CATEGORY_PRESETS[presetName as keyof typeof CATEGORY_PRESETS];
131
128
  } else if (presetName in REGION_PRESETS) {
132
129
  presetOptions = REGION_PRESETS[presetName as keyof typeof REGION_PRESETS];
133
130
  } else {
@@ -146,9 +143,7 @@ export function getPresetOptions(
146
143
  * @param type Tipe karakter pengganti
147
144
  * @returns Karakter pengganti
148
145
  */
149
- export function getReplacementChar(
150
- type: keyof typeof REPLACEMENT_CHARS = "asterisk",
151
- ): string {
146
+ export function getReplacementChar(type: keyof typeof REPLACEMENT_CHARS = 'asterisk'): string {
152
147
  return REPLACEMENT_CHARS[type] || REPLACEMENT_CHARS.asterisk;
153
148
  }
154
149
 
@@ -169,7 +164,7 @@ export function getRandomGrawlix(): string {
169
164
  * @returns String pengganti
170
165
  */
171
166
  export function makeRandomGrawlixString(length: number): string {
172
- let result = "";
167
+ let result = '';
173
168
  const grawlix = REPLACEMENT_CHARS.grawlix;
174
169
 
175
170
  for (let i = 0; i < length; i++) {
@@ -1,23 +1,34 @@
1
- import { ProfanityWord } from "../../types";
2
- import { general } from "../regions/general";
3
- import { jawa } from "../regions/jawa";
4
- import { sunda } from "../regions/sunda";
5
- import { betawi } from "../regions/betawi";
1
+ import { ProfanityWord } from '../../types';
2
+ import { general } from '../regions/general';
3
+ import { jawa } from '../regions/jawa';
4
+ import { sunda } from '../regions/sunda';
5
+ import { betawi } from '../regions/betawi';
6
+ import { minang } from '../regions/minang';
7
+ import madura from '../regions/madura';
8
+ import aceh from '../regions/aceh';
9
+ import bali from '../regions/bali';
10
+ import batak from '../regions/batak';
6
11
 
7
12
  export const blasphemy: ProfanityWord[] = [
8
- ...general.filter((word) => word.category === "blasphemy"),
9
- ...jawa.filter((word) => word.category === "blasphemy"),
10
- ...sunda.filter((word) => word.category === "blasphemy"),
11
- ...betawi.filter((word) => word.category === "blasphemy"),
13
+ ...general.filter((word) => word.category === 'blasphemy'),
14
+ ...jawa.filter((word) => word.category === 'blasphemy'),
15
+ ...sunda.filter((word) => word.category === 'blasphemy'),
16
+ ...betawi.filter((word) => word.category === 'blasphemy'),
17
+ ...minang.filter((word) => word.category === 'blasphemy'),
18
+ ...madura.filter((word) => word.category === 'blasphemy'),
19
+ ...sunda.filter((word) => word.category === 'blasphemy'),
20
+ ...aceh.filter((word) => word.category === 'blasphemy'),
21
+ ...bali.filter((word) => word.category === 'blasphemy'),
22
+ ...batak.filter((word) => word.category === 'blasphemy'),
12
23
 
13
24
  {
14
- word: "kafir",
15
- category: "blasphemy",
16
- region: "general",
25
+ word: 'kafir',
26
+ category: 'blasphemy',
27
+ region: 'general',
17
28
  severity: 0.6,
18
- aliases: ["kapir", "kafur"],
19
- description: "Istilah untuk orang yang tidak percaya pada Islam",
20
- context: "Dapat bersifat merendahkan ketika digunakan terhadap non-Muslim",
29
+ aliases: ['kapir', 'kafur'],
30
+ description: 'Istilah untuk orang yang tidak percaya pada Islam',
31
+ context: 'Dapat bersifat merendahkan ketika digunakan terhadap non-Muslim',
21
32
  },
22
33
  ];
23
34
 
@@ -1,80 +1,88 @@
1
- import { ProfanityWord } from "../../types";
2
- import { general } from "../regions/general";
3
- import { jawa } from "../regions/jawa";
4
- import { sunda } from "../regions/sunda";
5
- import { betawi } from "../regions/betawi";
1
+ import { ProfanityWord } from '../../types';
2
+ import { general } from '../regions/general';
3
+ import { jawa } from '../regions/jawa';
4
+ import { sunda } from '../regions/sunda';
5
+ import { betawi } from '../regions/betawi';
6
+ import minang from '../regions/minang';
7
+ import madura from '../regions/madura';
8
+ import aceh from '../regions/aceh';
9
+ import bali from '../regions/bali';
10
+ import batak from '../regions/batak';
6
11
 
7
12
  export const disgusting: ProfanityWord[] = [
8
- ...general.filter((word) => word.category === "disgusting"),
9
- ...jawa.filter((word) => word.category === "disgusting"),
10
- ...sunda.filter((word) => word.category === "disgusting"),
11
- ...betawi.filter((word) => word.category === "disgusting"),
13
+ ...general.filter((word) => word.category === 'disgusting'),
14
+ ...jawa.filter((word) => word.category === 'disgusting'),
15
+ ...sunda.filter((word) => word.category === 'disgusting'),
16
+ ...betawi.filter((word) => word.category === 'disgusting'),
17
+ ...minang.filter((word) => word.category === 'disgusting'),
18
+ ...madura.filter((word) => word.category === 'disgusting'),
19
+ ...sunda.filter((word) => word.category === 'disgusting'),
20
+ ...aceh.filter((word) => word.category === 'disgusting'),
21
+ ...bali.filter((word) => word.category === 'disgusting'),
22
+ ...batak.filter((word) => word.category === 'disgusting'),
12
23
 
13
24
  {
14
- word: "muntah",
15
- category: "disgusting",
16
- region: "general",
25
+ word: 'muntah',
26
+ category: 'disgusting',
27
+ region: 'general',
17
28
  severity: 0.4,
18
- aliases: ["muntaber", "memuntahkan"],
19
- description: "Muntahan atau tindakan muntah",
20
- context:
21
- "Digunakan untuk mengekspresikan rasa jijik atau menggambarkan tindakan tersebut",
29
+ aliases: ['muntaber', 'memuntahkan'],
30
+ description: 'Muntahan atau tindakan muntah',
31
+ context: 'Digunakan untuk mengekspresikan rasa jijik atau menggambarkan tindakan tersebut',
22
32
  },
23
33
  {
24
- word: "ingus",
25
- category: "disgusting",
26
- region: "general",
34
+ word: 'ingus',
35
+ category: 'disgusting',
36
+ region: 'general',
27
37
  severity: 0.4,
28
- aliases: ["ingusan", "beringus"],
29
- description: "Lendir hidung",
30
- context: "Digunakan untuk menggambarkan lendir hidung atau sebagai hinaan",
38
+ aliases: ['ingusan', 'beringus'],
39
+ description: 'Lendir hidung',
40
+ context: 'Digunakan untuk menggambarkan lendir hidung atau sebagai hinaan',
31
41
  },
32
42
  {
33
- word: "tai",
34
- category: "disgusting",
35
- region: "general",
43
+ word: 'tai',
44
+ category: 'disgusting',
45
+ region: 'general',
36
46
  severity: 0.8,
37
- aliases: ["tahi", "kotoran"],
38
- description: "Kotoran manusia",
39
- context: "Istilah vulgar untuk kotoran, sering digunakan sebagai hinaan",
47
+ aliases: ['tahi', 'kotoran'],
48
+ description: 'Kotoran manusia',
49
+ context: 'Istilah vulgar untuk kotoran, sering digunakan sebagai hinaan',
40
50
  },
41
51
  {
42
- word: "jembut",
43
- category: "disgusting",
44
- region: "general",
52
+ word: 'jembut',
53
+ category: 'disgusting',
54
+ region: 'general',
45
55
  severity: 1.0,
46
- aliases: ["jembud", "rambut kemaluan"],
47
- description: "Rambut kemaluan",
48
- context:
49
- "Istilah vulgar untuk rambut kemaluan, dianggap sangat tidak pantas",
56
+ aliases: ['jembud', 'rambut kemaluan'],
57
+ description: 'Rambut kemaluan',
58
+ context: 'Istilah vulgar untuk rambut kemaluan, dianggap sangat tidak pantas',
50
59
  },
51
60
  {
52
- word: "pecret",
53
- category: "disgusting",
54
- region: "sunda",
61
+ word: 'pecret',
62
+ category: 'disgusting',
63
+ region: 'sunda',
55
64
  severity: 0.8,
56
- aliases: ["mencret", "diare"],
57
- description: "Diare dalam bahasa Sunda",
58
- context: "Dianggap vulgar ketika disebutkan di depan umum",
65
+ aliases: ['mencret', 'diare'],
66
+ description: 'Diare dalam bahasa Sunda',
67
+ context: 'Dianggap vulgar ketika disebutkan di depan umum',
59
68
  },
60
69
  {
61
- word: "bacot",
62
- category: "disgusting",
63
- region: "betawi",
70
+ word: 'bacot',
71
+ category: 'disgusting',
72
+ region: 'betawi',
64
73
  severity: 0.8,
65
- aliases: ["cicing", "berisik"],
66
- description: "Mulut atau omongan berisik dalam konteks vulgar",
67
- context: "Istilah kasar yang digunakan untuk menyuruh seseorang diam",
74
+ aliases: ['cicing', 'berisik'],
75
+ description: 'Mulut atau omongan berisik dalam konteks vulgar',
76
+ context: 'Istilah kasar yang digunakan untuk menyuruh seseorang diam',
68
77
  },
69
78
  {
70
- word: "lendir",
71
- category: "disgusting",
72
- region: "general",
79
+ word: 'lendir',
80
+ category: 'disgusting',
81
+ region: 'general',
73
82
  severity: 0.3,
74
- aliases: ["berlendir", "cairan lengket"],
75
- description: "Lendir atau cairan lengket",
76
- context:
77
- "Dapat digunakan dalam konteks vulgar untuk menggambarkan cairan tubuh",
83
+ aliases: ['berlendir', 'cairan lengket'],
84
+ description: 'Lendir atau cairan lengket',
85
+ context: 'Dapat digunakan dalam konteks vulgar untuk menggambarkan cairan tubuh',
78
86
  },
79
87
  ];
80
88
 
@@ -1,70 +1,79 @@
1
- import { ProfanityWord } from "../../types";
2
- import { general } from "../regions/general";
3
- import { jawa } from "../regions/jawa";
4
- import { sunda } from "../regions/sunda";
5
- import { betawi } from "../regions/betawi";
1
+ import { ProfanityWord } from '../../types';
2
+ import { general } from '../regions/general';
3
+ import { jawa } from '../regions/jawa';
4
+ import { sunda } from '../regions/sunda';
5
+ import { betawi } from '../regions/betawi';
6
+ import { minang } from '../regions/minang';
7
+ import madura from '../regions/madura';
8
+ import aceh from '../regions/aceh';
9
+ import bali from '../regions/bali';
10
+ import batak from '../regions/batak';
6
11
 
7
12
  export const drugs: ProfanityWord[] = [
8
- ...general.filter((word) => word.category === "drugs"),
9
- ...jawa.filter((word) => word.category === "drugs"),
10
- ...sunda.filter((word) => word.category === "drugs"),
11
- ...betawi.filter((word) => word.category === "drugs"),
13
+ ...general.filter((word) => word.category === 'drugs'),
14
+ ...jawa.filter((word) => word.category === 'drugs'),
15
+ ...sunda.filter((word) => word.category === 'drugs'),
16
+ ...betawi.filter((word) => word.category === 'drugs'),
17
+ ...minang.filter((word) => word.category === 'drugs'),
18
+ ...madura.filter((word) => word.category === 'drugs'),
19
+ ...sunda.filter((word) => word.category === 'drugs'),
20
+ ...aceh.filter((word) => word.category === 'drugs'),
21
+ ...bali.filter((word) => word.category === 'drugs'),
22
+ ...batak.filter((word) => word.category === 'drugs'),
12
23
 
13
24
  {
14
- word: "ganja",
15
- category: "drugs",
16
- region: "general",
25
+ word: 'ganja',
26
+ category: 'drugs',
27
+ region: 'general',
17
28
  severity: 0.6,
18
- aliases: ["cimeng", "kanabis", "marijuana"],
19
- description: "Tanaman yang mengandung zat psikoaktif",
20
- context: "Digunakan untuk merujuk pada narkotika jenis cannabis",
29
+ aliases: ['cimeng', 'kanabis', 'marijuana'],
30
+ description: 'Tanaman yang mengandung zat psikoaktif',
31
+ context: 'Digunakan untuk merujuk pada narkotika jenis cannabis',
21
32
  },
22
33
  {
23
- word: "sabu",
24
- category: "drugs",
25
- region: "general",
34
+ word: 'sabu',
35
+ category: 'drugs',
36
+ region: 'general',
26
37
  severity: 0.8,
27
- aliases: ["crystal", "meth", "ss"],
28
- description: "Narkotika jenis metamfetamin",
29
- context: "Istilah untuk metamfetamin yang merupakan narkotika berbahaya",
38
+ aliases: ['crystal', 'meth', 'ss'],
39
+ description: 'Narkotika jenis metamfetamin',
40
+ context: 'Istilah untuk metamfetamin yang merupakan narkotika berbahaya',
30
41
  },
31
42
  {
32
- word: "inex",
33
- category: "drugs",
34
- region: "general",
43
+ word: 'inex',
44
+ category: 'drugs',
45
+ region: 'general',
35
46
  severity: 0.7,
36
- aliases: ["ekstasi", "pil"],
37
- description: "Obat terlarang yang mengandung MDMA",
38
- context: "Nama slang untuk obat terlarang ecstasy",
47
+ aliases: ['ekstasi', 'pil'],
48
+ description: 'Obat terlarang yang mengandung MDMA',
49
+ context: 'Nama slang untuk obat terlarang ecstasy',
39
50
  },
40
51
  {
41
- word: "sakaw",
42
- category: "drugs",
43
- region: "general",
52
+ word: 'sakaw',
53
+ category: 'drugs',
54
+ region: 'general',
44
55
  severity: 0.5,
45
- aliases: ["ketagihan", "menarik"],
46
- description: "Gejala putus obat pada pecandu",
47
- context:
48
- "Menggambarkan kondisi pecandu yang sedang mengalami gejala putus obat",
56
+ aliases: ['ketagihan', 'menarik'],
57
+ description: 'Gejala putus obat pada pecandu',
58
+ context: 'Menggambarkan kondisi pecandu yang sedang mengalami gejala putus obat',
49
59
  },
50
60
  {
51
- word: "ngepil",
52
- category: "drugs",
53
- region: "jawa",
61
+ word: 'ngepil',
62
+ category: 'drugs',
63
+ region: 'jawa',
54
64
  severity: 0.3,
55
- aliases: ["minum pil", "telan pil"],
56
- description: "Mengkonsumsi obat-obatan terlarang dalam bentuk pil",
57
- context:
58
- "Istilah dalam bahasa gaul untuk mengkonsumsi obat terlarang jenis tablet",
65
+ aliases: ['minum pil', 'telan pil'],
66
+ description: 'Mengkonsumsi obat-obatan terlarang dalam bentuk pil',
67
+ context: 'Istilah dalam bahasa gaul untuk mengkonsumsi obat terlarang jenis tablet',
59
68
  },
60
69
  {
61
- word: "nyimeng",
62
- category: "drugs",
63
- region: "sunda",
70
+ word: 'nyimeng',
71
+ category: 'drugs',
72
+ region: 'sunda',
64
73
  severity: 0.6,
65
- aliases: ["nyimang", "isap ganja"],
66
- description: "Mengisap ganja atau marijuana",
67
- context: "Istilah sunda untuk aktivitas mengkonsumsi ganja",
74
+ aliases: ['nyimang', 'isap ganja'],
75
+ description: 'Mengisap ganja atau marijuana',
76
+ context: 'Istilah sunda untuk aktivitas mengkonsumsi ganja',
68
77
  },
69
78
  ];
70
79