@sideid/id-profanity-filter 1.9.6 → 1.10.5
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/.eslintrc.js +30 -2
- package/README.md +45 -3
- package/dist/config/options.d.ts +24 -0
- package/dist/constants/wordList.d.ts +1 -1
- package/dist/core/analyzer.d.ts +1 -1
- package/dist/core/filter.d.ts +1 -1
- package/dist/core/matcher.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +411 -77
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +412 -76
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/utils/similarityUtils.d.ts +25 -0
- package/eslint.config.mjs +40 -0
- package/package.json +2 -2
- package/src/config/options.ts +2 -0
- package/src/constants/regions/general.ts +102 -2
- package/src/constants/regions/jawa.ts +10 -0
- package/src/constants/wordList.ts +15 -8
- package/src/core/analyzer.ts +1 -7
- package/src/core/filter.ts +178 -37
- package/src/core/matcher.ts +128 -58
- package/src/index.ts +21 -2
- package/src/types/index.ts +4 -2
- package/src/utils/regexUtils.ts +0 -1
- package/src/utils/similarityUtils.ts +97 -2
- package/test.js +184 -0
- package/src/constants/categories/index.ts +0 -31
- package/src/constants/regions/index.ts +0 -62
package/test.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// full-example.js
|
|
2
|
+
const { IDProfanityFilter, idFilter } = require('./dist');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Contoh Penggunaan Lengkap ID-Profanity-Filter
|
|
6
|
+
* ============================================
|
|
7
|
+
* File ini mencakup semua contoh penggunaan utama library.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
console.log('============ CONTOH PENGGUNAAN DASAR ============\n');
|
|
11
|
+
|
|
12
|
+
const filter = new IDProfanityFilter();
|
|
13
|
+
|
|
14
|
+
const teks =
|
|
15
|
+
'Dasar kontol kontol kntl babi asu ngentod kamu, jangan banyak bacot! perek';
|
|
16
|
+
|
|
17
|
+
// ===== 1. Cek apakah teks mengandung kata kotor =====
|
|
18
|
+
const hasProfanity = filter.isProfane(teks);
|
|
19
|
+
console.log('1. Apakah teks mengandung kata kotor?', hasProfanity);
|
|
20
|
+
|
|
21
|
+
// ===== 2. Filter kata kotor (mengganti dengan sensor) =====
|
|
22
|
+
const hasil = filter.filter(teks);
|
|
23
|
+
console.log('\n2. Hasil filter:');
|
|
24
|
+
console.log('- Teks asli:', teks);
|
|
25
|
+
console.log('- Teks tersensor:', hasil.filtered);
|
|
26
|
+
console.log('- Jumlah kata yang disensor:', hasil.censored);
|
|
27
|
+
console.log('- Detail penggantian:', hasil.replacements);
|
|
28
|
+
|
|
29
|
+
// ===== 3. Analisis konten =====
|
|
30
|
+
const analisis = filter.analyze(teks);
|
|
31
|
+
console.log('\n3. Hasil analisis:');
|
|
32
|
+
console.log('- Mengandung kata kotor:', analisis.hasProfanity);
|
|
33
|
+
console.log('- Kata kotor yang ditemukan:', analisis.matches);
|
|
34
|
+
console.log('- Kategori kata kotor:', analisis.categories);
|
|
35
|
+
console.log('- Daerah asal kata kotor:', analisis.regions);
|
|
36
|
+
console.log('- Skor keparahan:', analisis.severityScore.toFixed(2));
|
|
37
|
+
|
|
38
|
+
// console.log('\n============ PENGGUNAAN PRESET ============\n');
|
|
39
|
+
|
|
40
|
+
// // ===== 4. Menggunakan preset filter =====
|
|
41
|
+
// console.log('4. Menggunakan preset filter:');
|
|
42
|
+
|
|
43
|
+
// // Preset strict
|
|
44
|
+
// filter.usePreset('strict');
|
|
45
|
+
// console.log('- Preset strict:', filter.filter(teks).filtered);
|
|
46
|
+
|
|
47
|
+
// // Preset childSafe
|
|
48
|
+
// filter.usePreset('childSafe');
|
|
49
|
+
// console.log('- Preset childSafe:', filter.filter(teks).filtered);
|
|
50
|
+
|
|
51
|
+
// // Preset light
|
|
52
|
+
// filter.usePreset('light');
|
|
53
|
+
// console.log('- Preset light:', filter.filter(teks).filtered);
|
|
54
|
+
|
|
55
|
+
console.log('\n============ KUSTOMISASI FILTER ============\n');
|
|
56
|
+
|
|
57
|
+
// ===== 5. Kustomisasi filter =====
|
|
58
|
+
console.log('5. Kustomisasi filter:');
|
|
59
|
+
|
|
60
|
+
filter.setOptions({
|
|
61
|
+
replaceWith: '#', // Menggunakan # sebagai karakter pengganti
|
|
62
|
+
fullWordCensor: false, // Hanya menyensor sebagian kata
|
|
63
|
+
keepFirstAndLast: true, // Menyimpan huruf pertama dan terakhir
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log('- Filter dengan opsi kustom:', filter.filter(teks).filtered);
|
|
67
|
+
|
|
68
|
+
// Mendeteksi variasi penulisan
|
|
69
|
+
filter.setOptions({
|
|
70
|
+
detectLeetSpeak: true,
|
|
71
|
+
indonesianVariation: true,
|
|
72
|
+
detectSplit: true,
|
|
73
|
+
detectSimilarity: true,
|
|
74
|
+
useLevenshtein: true,
|
|
75
|
+
similarityThreshold: 0.85,
|
|
76
|
+
maxLevenshteinDistance: 2,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const teks2 =
|
|
80
|
+
'Dasar b4b1 kamu, j4nc0k! Ngent0d! k-o-n-t-o-l! k o n t o l k-0nt0l! anjiing kontool kwontol';
|
|
81
|
+
console.log('- Teks asli dengan variasi:', teks2);
|
|
82
|
+
console.log('- Hasil filter variasi:', filter.filter(teks2).filtered);
|
|
83
|
+
|
|
84
|
+
// ===== 6. Menggunakan whitelist =====
|
|
85
|
+
console.log('\n6. Menggunakan whitelist:');
|
|
86
|
+
|
|
87
|
+
filter.addToWhitelist('anjing');
|
|
88
|
+
const tekstBinatang =
|
|
89
|
+
'Anjing itu hewan peliharaan yang setia, tidak seperti bajingan itu';
|
|
90
|
+
|
|
91
|
+
console.log('- Teks dengan "anjing" dalam konteks binatang:', tekstBinatang);
|
|
92
|
+
console.log(
|
|
93
|
+
'- Hasil filter dengan whitelist:',
|
|
94
|
+
filter.filter(tekstBinatang).filtered,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// ===== 7. Menggunakan daftar kata kustom =====
|
|
98
|
+
console.log('\n7. Menggunakan daftar kata kustom:');
|
|
99
|
+
|
|
100
|
+
const customBadWords = ['jelek', 'buruk', 'sampah', 'payah'];
|
|
101
|
+
|
|
102
|
+
// Reset filter dan gunakan daftar kustom
|
|
103
|
+
filter.setOptions({
|
|
104
|
+
wordList: customBadWords,
|
|
105
|
+
replaceWith: '*',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const teksKustom = 'Film ini jelek dan payah sekali!';
|
|
109
|
+
console.log('- Teks asli:', teksKustom);
|
|
110
|
+
console.log('- Hasil filter kustom:', filter.filter(teksKustom).filtered);
|
|
111
|
+
|
|
112
|
+
console.log('\n============ ANALISIS LANJUTAN ============\n');
|
|
113
|
+
|
|
114
|
+
// ===== 8. Analisis per kalimat =====
|
|
115
|
+
console.log('8. Analisis per kalimat:');
|
|
116
|
+
|
|
117
|
+
filter.setOptions({}); // Reset ke default
|
|
118
|
+
const kalimat =
|
|
119
|
+
'Saya sangat suka filmnya. Tapi pemainnya seperti anjing, aktingnya buruk.';
|
|
120
|
+
console.log('- Kalimat:', kalimat);
|
|
121
|
+
|
|
122
|
+
const kalimatAnalisis = filter.analyzeBySentence(kalimat);
|
|
123
|
+
console.log('- Hasil analisis per kalimat:');
|
|
124
|
+
kalimatAnalisis.forEach((hasil, index) => {
|
|
125
|
+
console.log(` Kalimat ${index + 1}: "${hasil.sentence}"`);
|
|
126
|
+
console.log(` Mengandung kata kotor: ${hasil.hasProfanity}`);
|
|
127
|
+
if (hasil.hasProfanity) {
|
|
128
|
+
console.log(` Kata kotor: ${hasil.matches.join(', ')}`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// ===== 9. Analisis batch untuk komentar =====
|
|
133
|
+
console.log('\n9. Analisis batch:');
|
|
134
|
+
|
|
135
|
+
const komentar = [
|
|
136
|
+
'Film ini sangat bagus, ceritanya menarik sekali!',
|
|
137
|
+
'Dasar goblok, sialan kamu!',
|
|
138
|
+
'Anjing emang filmnya, sampah banget.',
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
console.log('- Batch teks:');
|
|
142
|
+
komentar.forEach((k, i) => console.log(` ${i + 1}. "${k}"`));
|
|
143
|
+
|
|
144
|
+
const hasilBatch = filter.batchAnalyze(komentar);
|
|
145
|
+
console.log('- Hasil analisis batch:');
|
|
146
|
+
console.log(` - Total teks: ${hasilBatch.totalTexts}`);
|
|
147
|
+
console.log(` - Teks mengandung kata kotor: ${hasilBatch.profaneTexts}`);
|
|
148
|
+
console.log(` - Teks bersih: ${hasilBatch.cleanTexts}`);
|
|
149
|
+
console.log(` - Kategori teratas: ${hasilBatch.topCategories.join(', ')}`);
|
|
150
|
+
console.log(` - Daerah teratas: ${hasilBatch.topRegions.join(', ')}`);
|
|
151
|
+
console.log(' - Kata kotor terbanyak:');
|
|
152
|
+
hasilBatch.mostFrequentWords.forEach((word) => {
|
|
153
|
+
console.log(` * "${word.word}": ${word.count} kali`);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ===== 10. Filter berdasarkan kategori dan daerah =====
|
|
157
|
+
console.log('\n10. Filter berdasarkan kategori dan daerah:');
|
|
158
|
+
|
|
159
|
+
// Filter untuk kata dari daerah Jawa saja
|
|
160
|
+
const filterJawa = new IDProfanityFilter({
|
|
161
|
+
regions: ['jawa'], // Hanya filter kata dari Jawa
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const contohTeksJawa = 'Dasar jancok, asu, bangsat, bacot!';
|
|
165
|
+
console.log('- Teks asli:', contohTeksJawa);
|
|
166
|
+
console.log(
|
|
167
|
+
'- Filter khusus kata Jawa:',
|
|
168
|
+
filterJawa.filter(contohTeksJawa).filtered,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Filter untuk kategori sexual saja
|
|
172
|
+
const filterSexual = new IDProfanityFilter({
|
|
173
|
+
categories: ['sexual'], // Hanya filter kata kategori seksual
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const contohTeksSexual =
|
|
177
|
+
'Kata kotor seperti anjing dan goblok tidak disensor, tapi bokep disensor.';
|
|
178
|
+
console.log('- Teks asli:', contohTeksSexual);
|
|
179
|
+
console.log(
|
|
180
|
+
'- Filter khusus kategori sexual:',
|
|
181
|
+
filterSexual.filter(contohTeksSexual).filtered,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
console.log('\n============ SELESAI ============');
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { sexual } from './sexual';
|
|
2
|
-
import { insult } from './insult';
|
|
3
|
-
// import { profanity } from './profanity';
|
|
4
|
-
// import { slur } from './slur';
|
|
5
|
-
// import { drugs } from './drugs';
|
|
6
|
-
// import { disgusting } from './disgusting';
|
|
7
|
-
// import { blasphemy } from './blasphemy';
|
|
8
|
-
|
|
9
|
-
export const categories = {
|
|
10
|
-
sexual, // Kata-kata berbau seksual
|
|
11
|
-
insult, // Kata-kata penghinaan
|
|
12
|
-
// profanity, // Umpatan umum
|
|
13
|
-
// slur, // Perkataan merendahkan berdasarkan identitas
|
|
14
|
-
// drugs, // Terkait narkoba
|
|
15
|
-
// disgusting, // Kata-kata menjijikkan
|
|
16
|
-
// blasphemy, // Penistaan agama
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { sexual, insult };
|
|
20
|
-
|
|
21
|
-
export const allCategoryWords = [
|
|
22
|
-
...sexual,
|
|
23
|
-
...insult,
|
|
24
|
-
// ...profanity,
|
|
25
|
-
// ...slur,
|
|
26
|
-
// ...drugs,
|
|
27
|
-
// ...disgusting,
|
|
28
|
-
// ...blasphemy,
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export default allCategoryWords;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { general } from './general';
|
|
2
|
-
import { jawa } from './jawa';
|
|
3
|
-
import { sunda } from './sunda';
|
|
4
|
-
import { betawi } from './betawi';
|
|
5
|
-
import { batak } from './batak';
|
|
6
|
-
// import { minang } from './minang';
|
|
7
|
-
// import { bali } from './bali';
|
|
8
|
-
// import { madura } from './madura';
|
|
9
|
-
// import { bugis } from './bugis';
|
|
10
|
-
// import { aceh } from './aceh';
|
|
11
|
-
// import { ambon } from './ambon';
|
|
12
|
-
// import { papua } from './papua';
|
|
13
|
-
// import { manado } from './manado';
|
|
14
|
-
// import { banjar } from './banjar';
|
|
15
|
-
// import { palembang } from './palembang';
|
|
16
|
-
// import { lampung } from './lampung';
|
|
17
|
-
// import { ntt } from './ntt';
|
|
18
|
-
// import { ntb } from './ntb';
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
general,
|
|
22
|
-
jawa,
|
|
23
|
-
sunda,
|
|
24
|
-
betawi,
|
|
25
|
-
batak,
|
|
26
|
-
// minang,
|
|
27
|
-
// bali,
|
|
28
|
-
// madura,
|
|
29
|
-
// bugis,
|
|
30
|
-
// aceh,
|
|
31
|
-
// ambon,
|
|
32
|
-
// papua,
|
|
33
|
-
// manado,
|
|
34
|
-
// banjar,
|
|
35
|
-
// palembang,
|
|
36
|
-
// lampung,
|
|
37
|
-
// ntt,
|
|
38
|
-
// ntb,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const allRegionWords = [
|
|
42
|
-
...general,
|
|
43
|
-
...jawa,
|
|
44
|
-
...sunda,
|
|
45
|
-
...betawi,
|
|
46
|
-
...batak,
|
|
47
|
-
// ...minang,
|
|
48
|
-
// ...bali,
|
|
49
|
-
// ...madura,
|
|
50
|
-
// ...bugis,
|
|
51
|
-
// ...aceh,
|
|
52
|
-
// ...ambon,
|
|
53
|
-
// ...papua,
|
|
54
|
-
// ...manado,
|
|
55
|
-
// ...banjar,
|
|
56
|
-
// ...palembang,
|
|
57
|
-
// ...lampung,
|
|
58
|
-
// ...ntt,
|
|
59
|
-
// ...ntb,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
export default allRegionWords;
|