@sideid/id-profanity-filter 1.12.0 → 1.13.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/CONTRIBUTING.md +91 -129
- package/README.md +160 -454
- package/dist/index.d.ts +11 -6
- package/dist/index.esm.js +161 -176
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +161 -176
- package/dist/index.js.map +1 -1
- package/dist/types/core/matcher.d.ts +5 -5
- package/dist/types/index.d.ts +5 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/utils/ahoCorasick.d.ts +10 -0
- package/eslint.config.mjs +1 -0
- package/examples/advanced.ts +4 -1
- package/examples/custom-list.ts +3 -3
- package/package.json +9 -2
- package/rollup.config.mjs +5 -1
- package/src/constants/categories/sexual.ts +1 -1
- package/src/constants/regions/general.ts +3 -3
- package/src/constants/wordList.ts +0 -27
- package/src/core/filter.ts +58 -178
- package/src/core/matcher.ts +69 -43
- package/src/index.ts +8 -0
- package/src/types/index.ts +1 -11
- package/src/utils/ahoCorasick.ts +37 -0
- package/src/utils/regexUtils.ts +1 -2
- package/test/matcher.test.ts +18 -0
- package/test/profanity-filter.test.ts +15 -0
- package/.eslintrc.js +0 -44
- package/src/constants/regions/ambon.ts +0 -0
- package/src/constants/regions/banjar.ts +0 -0
- package/src/constants/regions/bugis.ts +0 -0
- package/src/constants/regions/lampung.ts +0 -0
- package/src/constants/regions/manado.ts +0 -0
- package/src/constants/regions/ntb.ts +0 -0
- package/src/constants/regions/ntt.ts +0 -0
- package/src/constants/regions/palembang.ts +0 -0
- package/src/constants/regions/papua.ts +0 -0
package/test/matcher.test.ts
CHANGED
|
@@ -66,6 +66,24 @@ describe('Matcher Core', () => {
|
|
|
66
66
|
expect(resultsWithGeneral).toContain('anjing');
|
|
67
67
|
expect(resultsWithGeneral).not.toContain('jancok');
|
|
68
68
|
});
|
|
69
|
+
|
|
70
|
+
test('should not trigger false positives on innocent words with substring matches by default', () => {
|
|
71
|
+
expect(findProfanity('saya mau masuk ke rumah')).toEqual([]);
|
|
72
|
+
expect(findProfanity('saya tidur di kasur')).toEqual([]);
|
|
73
|
+
expect(findProfanity('kunjungi website kami')).toEqual([]);
|
|
74
|
+
expect(findProfanity('barang ini asli')).toEqual([]);
|
|
75
|
+
expect(findProfanity('agama islam')).toEqual([]);
|
|
76
|
+
expect(findProfanity('saya sudah makan')).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('should detect custom wordList without built-in leakage', () => {
|
|
80
|
+
const results = findProfanity('film ini jelek dan payah anjing', {
|
|
81
|
+
wordList: ['jelek', 'payah'],
|
|
82
|
+
});
|
|
83
|
+
expect(results).toContain('jelek');
|
|
84
|
+
expect(results).toContain('payah');
|
|
85
|
+
expect(results).not.toContain('anjing');
|
|
86
|
+
});
|
|
69
87
|
});
|
|
70
88
|
|
|
71
89
|
describe('findProfanityWithMetadata function', () => {
|
|
@@ -49,6 +49,21 @@ describe('IDProfanityFilter', () => {
|
|
|
49
49
|
expect(result.filtered).not.toContain('anjing');
|
|
50
50
|
expect(result.filtered).not.toEqual('Dasar anjing kamu!');
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
test('should reset options to default with resetOptions', () => {
|
|
54
|
+
filter.setOptions({ replaceWith: '#' });
|
|
55
|
+
expect(filter.filter('anjing').filtered).toBe('######');
|
|
56
|
+
filter.resetOptions();
|
|
57
|
+
expect(filter.filter('anjing').filtered).toBe('******');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should censor custom wordList correctly', () => {
|
|
61
|
+
filter.resetOptions();
|
|
62
|
+
filter.setWordList(['jelek', 'payah']);
|
|
63
|
+
const result = filter.filter('Film itu sangat jelek dan payah!');
|
|
64
|
+
expect(result.filtered).toBe('Film itu sangat ***** dan *****!');
|
|
65
|
+
expect(result.censored).toBe(2);
|
|
66
|
+
});
|
|
52
67
|
});
|
|
53
68
|
|
|
54
69
|
describe('preset functionality', () => {
|
package/.eslintrc.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
parser: '@typescript-eslint/parser',
|
|
3
|
-
parserOptions: {
|
|
4
|
-
ecmaVersion: 2020,
|
|
5
|
-
sourceType: 'module',
|
|
6
|
-
project: './tsconfig.json',
|
|
7
|
-
},
|
|
8
|
-
extends: [
|
|
9
|
-
'eslint:recommended',
|
|
10
|
-
'plugin:@typescript-eslint/recommended',
|
|
11
|
-
'prettier', // Disables ESLint rules that might conflict with Prettier
|
|
12
|
-
],
|
|
13
|
-
plugins: ['@typescript-eslint'],
|
|
14
|
-
env: {
|
|
15
|
-
node: true,
|
|
16
|
-
jest: true,
|
|
17
|
-
},
|
|
18
|
-
rules: {
|
|
19
|
-
// Enforce consistent code style
|
|
20
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
21
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
22
|
-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
23
|
-
|
|
24
|
-
// Allow certain TypeScript patterns
|
|
25
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
26
|
-
|
|
27
|
-
// General ESLint rules
|
|
28
|
-
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
29
|
-
'prefer-const': 'warn',
|
|
30
|
-
'no-var': 'error',
|
|
31
|
-
|
|
32
|
-
// Make sure imports are properly sorted
|
|
33
|
-
'sort-imports': [
|
|
34
|
-
'off',
|
|
35
|
-
{
|
|
36
|
-
ignoreCase: false,
|
|
37
|
-
ignoreDeclarationSort: true,
|
|
38
|
-
ignoreMemberSort: false,
|
|
39
|
-
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
ignorePatterns: ['dist/', 'node_modules/', '*.js', '*.d.ts'],
|
|
44
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|