glin-profanity 1.1.1 → 1.1.3
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/lib/data/Norwegian.json +17 -0
- package/lib/data/arabic.json +157 -0
- package/lib/data/chinese.json +298 -0
- package/lib/data/czech.json +45 -0
- package/lib/data/danish.json +24 -0
- package/lib/data/dictionary.d.ts +26 -0
- package/lib/data/dictionary.d.ts.map +1 -0
- package/{src/data/dictionary.ts → lib/data/dictionary.js} +23 -22
- package/lib/data/dictionary.js.map +1 -0
- package/lib/data/english.json +382 -0
- package/lib/data/esperanto.json +41 -0
- package/lib/data/finnish.json +134 -0
- package/lib/data/french.json +99 -0
- package/lib/data/german.json +69 -0
- package/lib/data/hindi.json +100 -0
- package/lib/data/hungarian.json +100 -0
- package/lib/data/italian.json +184 -0
- package/lib/data/japanese.json +189 -0
- package/lib/data/korean.json +76 -0
- package/lib/data/persian.json +49 -0
- package/lib/data/polish.json +57 -0
- package/lib/data/portuguese.json +78 -0
- package/lib/data/russian.json +156 -0
- package/lib/data/swedish.json +47 -0
- package/lib/data/thai.json +35 -0
- package/lib/data/turkish.json +195 -0
- package/lib/filters/Filter.d.ts +27 -0
- package/lib/filters/Filter.d.ts.map +1 -0
- package/lib/filters/Filter.js +73 -0
- package/lib/filters/Filter.js.map +1 -0
- package/lib/hooks/useProfanityChecker.d.ts +18 -0
- package/lib/hooks/useProfanityChecker.d.ts.map +1 -0
- package/lib/hooks/useProfanityChecker.js +38 -0
- package/lib/hooks/useProfanityChecker.js.map +1 -0
- package/{src/index.ts → lib/index.d.ts} +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/types/types.d.ts +10 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +2 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +26 -55
- package/.babelrc +0 -3
- package/.eslintrc.json +0 -27
- package/.gitattributes +0 -1
- package/.github/workflows/dependency-review.yml +0 -39
- package/.github/workflows/publish.yml +0 -31
- package/.husky/commit-msg +0 -5
- package/.husky/post-commit +0 -4
- package/.husky/pre-commit +0 -5
- package/.nvmrc +0 -1
- package/.prettierignore +0 -13
- package/.prettierrc +0 -15
- package/CODE_OF_CONDUCT.md +0 -80
- package/LICENSE +0 -21
- package/README.md +0 -163
- package/SECURITY.md +0 -14
- package/changelog.config.cjs +0 -89
- package/commitlint.config.cjs +0 -138
- package/dist/index.html +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.LICENSE.txt +0 -11
- package/public/index.html +0 -11
- package/src/App.tsx +0 -140
- package/src/data/Norwegian.json +0 -17
- package/src/data/arabic.json +0 -157
- package/src/data/chinese.json +0 -298
- package/src/data/czech.json +0 -45
- package/src/data/danish.json +0 -24
- package/src/data/english.json +0 -382
- package/src/data/esperanto.json +0 -41
- package/src/data/finnish.json +0 -134
- package/src/data/french.json +0 -99
- package/src/data/german.json +0 -69
- package/src/data/hindi.json +0 -100
- package/src/data/hungarian.json +0 -100
- package/src/data/italian.json +0 -184
- package/src/data/japanese.json +0 -189
- package/src/data/korean.json +0 -76
- package/src/data/persian.json +0 -49
- package/src/data/polish.json +0 -57
- package/src/data/portuguese.json +0 -78
- package/src/data/russian.json +0 -156
- package/src/data/spanish.json +0 -72
- package/src/data/swedish.json +0 -47
- package/src/data/thai.json +0 -35
- package/src/data/turkish.json +0 -195
- package/src/filters/Filter.ts +0 -92
- package/src/hooks/useProfanityChecker.ts +0 -44
- package/src/index.tsx +0 -10
- package/src/types/types.ts +0 -30
- package/tsconfig.json +0 -27
- package/webpack.config.js +0 -37
package/src/filters/Filter.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import dictionary from '../data/dictionary';
|
|
2
|
-
import { Language, CheckProfanityResult } from '../types/types';
|
|
3
|
-
|
|
4
|
-
interface FilterConfig {
|
|
5
|
-
languages?: Language[];
|
|
6
|
-
allLanguages?: boolean;
|
|
7
|
-
caseSensitive?: boolean;
|
|
8
|
-
wordBoundaries?: boolean;
|
|
9
|
-
customWords?: string[];
|
|
10
|
-
replaceWith?: string;
|
|
11
|
-
severityLevels?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class Filter {
|
|
15
|
-
private words: Map<string, number>;
|
|
16
|
-
private caseSensitive: boolean;
|
|
17
|
-
private wordBoundaries: boolean;
|
|
18
|
-
private replaceWith?: string;
|
|
19
|
-
private severityLevels: boolean;
|
|
20
|
-
|
|
21
|
-
constructor(config?: FilterConfig) {
|
|
22
|
-
let words: string[] = [];
|
|
23
|
-
this.caseSensitive = config?.caseSensitive ?? false;
|
|
24
|
-
this.wordBoundaries = config?.wordBoundaries ?? true;
|
|
25
|
-
this.replaceWith = config?.replaceWith;
|
|
26
|
-
this.severityLevels = config?.severityLevels ?? false;
|
|
27
|
-
|
|
28
|
-
if (config?.allLanguages) {
|
|
29
|
-
for (const lang in dictionary) {
|
|
30
|
-
if (dictionary.hasOwnProperty(lang)) {
|
|
31
|
-
words = [...words, ...dictionary[lang as Language]];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
const languages = config?.languages || ['english'];
|
|
36
|
-
const languagesChecks = new Set<Language>(languages);
|
|
37
|
-
if (languagesChecks.size !== 0) {
|
|
38
|
-
languagesChecks.forEach(lang => {
|
|
39
|
-
words = [...words, ...dictionary[lang]];
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (config?.customWords) {
|
|
45
|
-
words = [...words, ...config.customWords];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.words = new Map(words.map(word => [word, 1])); // Default severity level is 1
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private getRegex(word: string): RegExp {
|
|
52
|
-
const flags = this.caseSensitive ? 'g' : 'gi';
|
|
53
|
-
const boundary = this.wordBoundaries ? '\\b' : '';
|
|
54
|
-
return new RegExp(`${boundary}${word.replace(/(\W)/g, '\\$1')}${boundary}`, flags);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isProfane(value: string): boolean {
|
|
58
|
-
for (const word of this.words.keys()) {
|
|
59
|
-
if (this.getRegex(word).test(value)) return true;
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
checkProfanity(text: string): CheckProfanityResult {
|
|
65
|
-
const words = text.split(/\s+/);
|
|
66
|
-
const profaneWords: string[] = [];
|
|
67
|
-
const severityMap: { [word: string]: number } = {};
|
|
68
|
-
|
|
69
|
-
for (const word of words) {
|
|
70
|
-
if (this.words.has(word.toLowerCase())) {
|
|
71
|
-
profaneWords.push(word);
|
|
72
|
-
severityMap[word] = this.words.get(word.toLowerCase())!;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let processedText = text;
|
|
77
|
-
if (this.replaceWith) {
|
|
78
|
-
for (const word of profaneWords) {
|
|
79
|
-
processedText = processedText.replace(this.getRegex(word), this.replaceWith);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
containsProfanity: profaneWords.length > 0,
|
|
85
|
-
profaneWords,
|
|
86
|
-
processedText: this.replaceWith ? processedText : undefined,
|
|
87
|
-
severityMap: this.severityLevels ? severityMap : undefined,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { Filter };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { Filter } from '../filters/Filter';
|
|
3
|
-
import { CheckProfanityResult, Language } from '../types/types';
|
|
4
|
-
|
|
5
|
-
interface ProfanityCheckerConfig {
|
|
6
|
-
languages?: Language[];
|
|
7
|
-
allLanguages?: boolean;
|
|
8
|
-
caseSensitive?: boolean;
|
|
9
|
-
wordBoundaries?: boolean;
|
|
10
|
-
customWords?: string[];
|
|
11
|
-
replaceWith?: string;
|
|
12
|
-
severityLevels?: boolean;
|
|
13
|
-
customActions?: (result: CheckProfanityResult) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const useProfanityChecker = (config?: ProfanityCheckerConfig) => {
|
|
17
|
-
const [result, setResult] = useState<CheckProfanityResult | null>(null);
|
|
18
|
-
const filter = new Filter(config);
|
|
19
|
-
|
|
20
|
-
const checkText = (text: string) => {
|
|
21
|
-
const checkResult = filter.checkProfanity(text);
|
|
22
|
-
setResult(checkResult);
|
|
23
|
-
if (config?.customActions) {
|
|
24
|
-
config.customActions(checkResult);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const checkTextAsync = async (text: string) => {
|
|
29
|
-
return new Promise<CheckProfanityResult>((resolve) => {
|
|
30
|
-
const checkResult = filter.checkProfanity(text);
|
|
31
|
-
setResult(checkResult);
|
|
32
|
-
if (config?.customActions) {
|
|
33
|
-
config.customActions(checkResult);
|
|
34
|
-
}
|
|
35
|
-
resolve(checkResult);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
result,
|
|
41
|
-
checkText,
|
|
42
|
-
checkTextAsync,
|
|
43
|
-
};
|
|
44
|
-
};
|
package/src/index.tsx
DELETED
package/src/types/types.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/types/types.ts
|
|
2
|
-
export interface CheckProfanityResult {
|
|
3
|
-
containsProfanity: boolean;
|
|
4
|
-
profaneWords: string[];
|
|
5
|
-
processedText?: string;
|
|
6
|
-
severityMap?: { [word: string]: number };
|
|
7
|
-
}
|
|
8
|
-
export type Language =
|
|
9
|
-
| 'arabic'
|
|
10
|
-
| 'chinese'
|
|
11
|
-
| 'czech'
|
|
12
|
-
| 'danish'
|
|
13
|
-
| 'english'
|
|
14
|
-
| 'esperanto'
|
|
15
|
-
| 'finnish'
|
|
16
|
-
| 'french'
|
|
17
|
-
| 'german'
|
|
18
|
-
| 'hindi'
|
|
19
|
-
| 'hungarian'
|
|
20
|
-
| 'italian'
|
|
21
|
-
| 'japanese'
|
|
22
|
-
| 'korean'
|
|
23
|
-
| 'norwegian'
|
|
24
|
-
| 'persian'
|
|
25
|
-
| 'polish'
|
|
26
|
-
| 'portuguese'
|
|
27
|
-
| 'russian'
|
|
28
|
-
| 'turkish'
|
|
29
|
-
| 'swedish'
|
|
30
|
-
| 'thai';
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2015",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"es2015"
|
|
8
|
-
],
|
|
9
|
-
"jsx": "react",
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"rootDir": "./src",
|
|
12
|
-
"strict": true,
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"forceConsistentCasingInFileNames": true,
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"allowSyntheticDefaultImports": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"src"
|
|
22
|
-
],
|
|
23
|
-
"exclude": [
|
|
24
|
-
"node_modules",
|
|
25
|
-
"dist"
|
|
26
|
-
]
|
|
27
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
entry: './src/index.ts',
|
|
6
|
-
output: {
|
|
7
|
-
path: path.resolve(__dirname, 'dist'),
|
|
8
|
-
filename: 'index.js',
|
|
9
|
-
libraryTarget: 'umd',
|
|
10
|
-
globalObject: 'this',
|
|
11
|
-
library: 'Glin-profanity'
|
|
12
|
-
},
|
|
13
|
-
resolve: {
|
|
14
|
-
extensions: ['.ts', '.tsx', '.js']
|
|
15
|
-
},
|
|
16
|
-
module: {
|
|
17
|
-
rules: [
|
|
18
|
-
{
|
|
19
|
-
test: /\.tsx?$/,
|
|
20
|
-
exclude: /node_modules/,
|
|
21
|
-
use: 'babel-loader'
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
plugins: [
|
|
26
|
-
new HtmlWebpackPlugin({
|
|
27
|
-
template: './public/index.html'
|
|
28
|
-
})
|
|
29
|
-
],
|
|
30
|
-
devServer: {
|
|
31
|
-
static: {
|
|
32
|
-
directory: path.join(__dirname, 'dist')
|
|
33
|
-
},
|
|
34
|
-
compress: true,
|
|
35
|
-
port: 9000
|
|
36
|
-
}
|
|
37
|
-
};
|