@sideid/id-profanity-filter 1.10.4 → 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/package.json +1 -1
- package/src/constants/wordList.ts +8 -8
- package/src/core/analyzer.ts +8 -8
- package/src/core/filter.ts +12 -12
- package/src/core/matcher.ts +6 -6
- package/src/index.ts +13 -13
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ProfanityWord } from
|
|
2
|
-
import { sexualWords } from
|
|
3
|
-
import { insultWords } from
|
|
1
|
+
import { ProfanityWord } from "../types";
|
|
2
|
+
import { sexualWords } from "./categories/sexual";
|
|
3
|
+
import { insultWords } from "./categories/insult";
|
|
4
4
|
// import { profanityWords } from './categories/profanity';
|
|
5
5
|
// import { slurWords } from './categories/slur';
|
|
6
6
|
// import { drugsWords } from './categories/drugs';
|
|
7
7
|
// import { disgustingWords } from './categories/disgusting';
|
|
8
8
|
// import { blasphemyWords } from './categories/blasphemy';
|
|
9
9
|
|
|
10
|
-
import { general, generalWords } from
|
|
11
|
-
import { jawa, jawaWords } from
|
|
12
|
-
import { sunda, sundaWords } from
|
|
13
|
-
import { betawi, betawiWords } from
|
|
14
|
-
import { batak, batakWords } from
|
|
10
|
+
import { general, generalWords } from "./regions/general";
|
|
11
|
+
import { jawa, jawaWords } from "./regions/jawa";
|
|
12
|
+
import { sunda, sundaWords } from "./regions/sunda";
|
|
13
|
+
import { betawi, betawiWords } from "./regions/betawi";
|
|
14
|
+
import { batak, batakWords } from "./regions/batak";
|
|
15
15
|
// import { minang, minangWords } from './regions/minang';
|
|
16
16
|
// import { bali, baliWords } from './regions/bali';
|
|
17
17
|
// import { madura, maduraWords } from './regions/madura';
|
package/src/core/analyzer.ts
CHANGED
|
@@ -3,18 +3,18 @@ import {
|
|
|
3
3
|
AnalysisResult,
|
|
4
4
|
ProfanityCategory,
|
|
5
5
|
Region,
|
|
6
|
-
} from
|
|
6
|
+
} from "../types";
|
|
7
7
|
import {
|
|
8
8
|
findProfanity,
|
|
9
9
|
findProfanityWithMetadata,
|
|
10
10
|
findCategories,
|
|
11
11
|
findRegions,
|
|
12
12
|
calculateSeverity,
|
|
13
|
-
} from
|
|
14
|
-
import { splitIntoSentences } from
|
|
15
|
-
import { findPossibleProfanityBySimiliarity } from
|
|
16
|
-
import { createContextRegex } from
|
|
17
|
-
import { DEFAULT_OPTIONS } from
|
|
13
|
+
} from "./matcher";
|
|
14
|
+
import { splitIntoSentences } from "../utils/stringUtils";
|
|
15
|
+
import { findPossibleProfanityBySimiliarity } from "../utils/similarityUtils";
|
|
16
|
+
import { createContextRegex } from "../utils/regexUtils";
|
|
17
|
+
import { DEFAULT_OPTIONS } from "../config/options";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Menganalisis teks untuk kata kotor
|
|
@@ -200,9 +200,9 @@ export function analyzeWithContext(
|
|
|
200
200
|
|
|
201
201
|
let match;
|
|
202
202
|
while ((match = regex.exec(text)) !== null) {
|
|
203
|
-
const beforeContext = match[1] ||
|
|
203
|
+
const beforeContext = match[1] || "";
|
|
204
204
|
const wordMatch = match[2];
|
|
205
|
-
const afterContext = match[3] ||
|
|
205
|
+
const afterContext = match[3] || "";
|
|
206
206
|
|
|
207
207
|
result.push({
|
|
208
208
|
word: wordMatch,
|
package/src/core/filter.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FilterOptions, FilterResult, ProfanityWord } from
|
|
2
|
-
import { findProfanity, findProfanityWithMetadata } from
|
|
3
|
-
import { censorWord, escapeRegExp } from
|
|
4
|
-
import { createWordRegex } from
|
|
5
|
-
import { DEFAULT_OPTIONS, makeRandomGrawlixString } from
|
|
1
|
+
import { FilterOptions, FilterResult, ProfanityWord } from "../types";
|
|
2
|
+
import { findProfanity, findProfanityWithMetadata } from "./matcher";
|
|
3
|
+
import { censorWord, escapeRegExp } from "../utils/stringUtils";
|
|
4
|
+
import { createWordRegex } from "../utils/regexUtils";
|
|
5
|
+
import { DEFAULT_OPTIONS, makeRandomGrawlixString } from "../config/options";
|
|
6
6
|
|
|
7
7
|
interface FindProfanityFunction {
|
|
8
8
|
(text: string, options?: FilterOptions): string[];
|
|
@@ -21,7 +21,7 @@ export function filter(
|
|
|
21
21
|
options: FilterOptions = {},
|
|
22
22
|
): FilterResult {
|
|
23
23
|
const {
|
|
24
|
-
replaceWith =
|
|
24
|
+
replaceWith = "*",
|
|
25
25
|
fullWordCensor = true,
|
|
26
26
|
detectLeetSpeak = true,
|
|
27
27
|
whitelist = [],
|
|
@@ -86,7 +86,7 @@ export function filter(
|
|
|
86
86
|
const uniqueVariants = [...new Set(variants)];
|
|
87
87
|
|
|
88
88
|
uniqueVariants.forEach((variant) => {
|
|
89
|
-
const regex = new RegExp(`\\b${escapeRegExp(variant)}\\b`,
|
|
89
|
+
const regex = new RegExp(`\\b${escapeRegExp(variant)}\\b`, "gi");
|
|
90
90
|
|
|
91
91
|
let match;
|
|
92
92
|
while ((match = regex.exec(filteredText)) !== null) {
|
|
@@ -112,7 +112,7 @@ export function filter(
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
filteredText = filteredText.replace(
|
|
115
|
-
new RegExp(`\\b${escapeRegExp(originalWord)}\\b`,
|
|
115
|
+
new RegExp(`\\b${escapeRegExp(originalWord)}\\b`, "g"),
|
|
116
116
|
censoredWord,
|
|
117
117
|
);
|
|
118
118
|
}
|
|
@@ -152,7 +152,7 @@ export function filter(
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
filteredText = filteredText.replace(
|
|
155
|
-
new RegExp(escapeRegExp(originalWord),
|
|
155
|
+
new RegExp(escapeRegExp(originalWord), "g"),
|
|
156
156
|
censoredWord,
|
|
157
157
|
);
|
|
158
158
|
}
|
|
@@ -191,7 +191,7 @@ export function filter(
|
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
filteredText = filteredText.replace(
|
|
194
|
-
new RegExp(escapeRegExp(originalWord),
|
|
194
|
+
new RegExp(escapeRegExp(originalWord), "g"),
|
|
195
195
|
censoredWord,
|
|
196
196
|
);
|
|
197
197
|
}
|
|
@@ -215,7 +215,7 @@ export function filter(
|
|
|
215
215
|
variants.forEach((variant) => {
|
|
216
216
|
const exactVariantRegex = new RegExp(
|
|
217
217
|
`\\b${escapeRegExp(variant)}\\b`,
|
|
218
|
-
|
|
218
|
+
"gi",
|
|
219
219
|
);
|
|
220
220
|
|
|
221
221
|
let match;
|
|
@@ -242,7 +242,7 @@ export function filter(
|
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
filteredText = filteredText.replace(
|
|
245
|
-
new RegExp(`\\b${escapeRegExp(originalWord)}\\b`,
|
|
245
|
+
new RegExp(`\\b${escapeRegExp(originalWord)}\\b`, "g"),
|
|
246
246
|
censoredWord,
|
|
247
247
|
);
|
|
248
248
|
}
|
package/src/core/matcher.ts
CHANGED
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
ProfanityCategory,
|
|
4
4
|
Region,
|
|
5
5
|
FilterOptions,
|
|
6
|
-
} from
|
|
6
|
+
} from "../types";
|
|
7
7
|
|
|
8
|
-
import { wordObjects } from
|
|
9
|
-
import { normalizeText } from
|
|
10
|
-
import { createWordRegex } from
|
|
8
|
+
import { wordObjects } from "../constants/wordList";
|
|
9
|
+
import { normalizeText } from "../utils/stringUtils";
|
|
10
|
+
import { createWordRegex } from "../utils/regexUtils";
|
|
11
11
|
import {
|
|
12
12
|
findPossibleProfanityBySimiliarity,
|
|
13
13
|
findProfanityByLevenshteinDistance,
|
|
14
|
-
} from
|
|
15
|
-
import { DEFAULT_OPTIONS } from
|
|
14
|
+
} from "../utils/similarityUtils";
|
|
15
|
+
import { DEFAULT_OPTIONS } from "../config/options";
|
|
16
16
|
|
|
17
17
|
interface FindProfanityFunction {
|
|
18
18
|
(text: string, options?: FilterOptions): string[];
|
package/src/index.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
|
|
10
|
-
import { filter, isProfane } from
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./core/matcher";
|
|
3
|
+
export * from "./core/filter";
|
|
4
|
+
export * from "./core/analyzer";
|
|
5
|
+
export * from "./utils/stringUtils";
|
|
6
|
+
export * from "./utils/regexUtils";
|
|
7
|
+
export * from "./utils/similarityUtils";
|
|
8
|
+
export * from "./config/options";
|
|
9
|
+
|
|
10
|
+
import { filter, isProfane } from "./core/filter";
|
|
11
11
|
import {
|
|
12
12
|
analyze,
|
|
13
13
|
batchAnalyze,
|
|
14
14
|
analyzeBySentence,
|
|
15
15
|
analyzeWithContext,
|
|
16
|
-
} from
|
|
17
|
-
import { FilterOptions, FilterResult, AnalysisResult } from
|
|
16
|
+
} from "./core/analyzer";
|
|
17
|
+
import { FilterOptions, FilterResult, AnalysisResult } from "./types";
|
|
18
18
|
import {
|
|
19
19
|
DEFAULT_OPTIONS,
|
|
20
20
|
FILTER_PRESETS,
|
|
21
21
|
CATEGORY_PRESETS,
|
|
22
22
|
REGION_PRESETS,
|
|
23
23
|
getPresetOptions,
|
|
24
|
-
} from
|
|
24
|
+
} from "./config/options";
|
|
25
25
|
|
|
26
26
|
export class IDProfanityFilter {
|
|
27
27
|
private options: FilterOptions;
|