glin-profanity 1.1.2 → 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.
Files changed (95) hide show
  1. package/lib/data/Norwegian.json +17 -0
  2. package/lib/data/arabic.json +157 -0
  3. package/lib/data/chinese.json +298 -0
  4. package/lib/data/czech.json +45 -0
  5. package/lib/data/danish.json +24 -0
  6. package/lib/data/dictionary.d.ts +26 -0
  7. package/lib/data/dictionary.d.ts.map +1 -0
  8. package/{src/data/dictionary.ts → lib/data/dictionary.js} +23 -22
  9. package/lib/data/dictionary.js.map +1 -0
  10. package/lib/data/english.json +382 -0
  11. package/lib/data/esperanto.json +41 -0
  12. package/lib/data/finnish.json +134 -0
  13. package/lib/data/french.json +99 -0
  14. package/lib/data/german.json +69 -0
  15. package/lib/data/hindi.json +100 -0
  16. package/lib/data/hungarian.json +100 -0
  17. package/lib/data/italian.json +184 -0
  18. package/lib/data/japanese.json +189 -0
  19. package/lib/data/korean.json +76 -0
  20. package/lib/data/persian.json +49 -0
  21. package/lib/data/polish.json +57 -0
  22. package/lib/data/portuguese.json +78 -0
  23. package/lib/data/russian.json +156 -0
  24. package/lib/data/swedish.json +47 -0
  25. package/lib/data/thai.json +35 -0
  26. package/lib/data/turkish.json +195 -0
  27. package/lib/filters/Filter.d.ts +27 -0
  28. package/lib/filters/Filter.d.ts.map +1 -0
  29. package/lib/filters/Filter.js +73 -0
  30. package/lib/filters/Filter.js.map +1 -0
  31. package/lib/hooks/useProfanityChecker.d.ts +18 -0
  32. package/lib/hooks/useProfanityChecker.d.ts.map +1 -0
  33. package/lib/hooks/useProfanityChecker.js +38 -0
  34. package/lib/hooks/useProfanityChecker.js.map +1 -0
  35. package/{src/index.ts → lib/index.d.ts} +1 -0
  36. package/lib/index.d.ts.map +1 -0
  37. package/lib/index.js +3 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/types/types.d.ts +10 -0
  40. package/lib/types/types.d.ts.map +1 -0
  41. package/lib/types/types.js +2 -0
  42. package/lib/types/types.js.map +1 -0
  43. package/package.json +26 -55
  44. package/.babelrc +0 -3
  45. package/.eslintrc.json +0 -27
  46. package/.gitattributes +0 -1
  47. package/.github/workflows/dependency-review.yml +0 -39
  48. package/.github/workflows/publish.yml +0 -31
  49. package/.husky/commit-msg +0 -5
  50. package/.husky/post-commit +0 -4
  51. package/.husky/pre-commit +0 -5
  52. package/.nvmrc +0 -1
  53. package/.prettierignore +0 -13
  54. package/.prettierrc +0 -15
  55. package/CODE_OF_CONDUCT.md +0 -80
  56. package/LICENSE +0 -21
  57. package/README.md +0 -169
  58. package/SECURITY.md +0 -14
  59. package/changelog.config.cjs +0 -89
  60. package/commitlint.config.cjs +0 -138
  61. package/dist/index.html +0 -1
  62. package/dist/index.js +0 -2
  63. package/dist/index.js.LICENSE.txt +0 -11
  64. package/public/index.html +0 -11
  65. package/src/App.tsx +0 -140
  66. package/src/data/Norwegian.json +0 -17
  67. package/src/data/arabic.json +0 -157
  68. package/src/data/chinese.json +0 -298
  69. package/src/data/czech.json +0 -45
  70. package/src/data/danish.json +0 -24
  71. package/src/data/english.json +0 -382
  72. package/src/data/esperanto.json +0 -41
  73. package/src/data/finnish.json +0 -134
  74. package/src/data/french.json +0 -99
  75. package/src/data/german.json +0 -69
  76. package/src/data/hindi.json +0 -100
  77. package/src/data/hungarian.json +0 -100
  78. package/src/data/italian.json +0 -184
  79. package/src/data/japanese.json +0 -189
  80. package/src/data/korean.json +0 -76
  81. package/src/data/persian.json +0 -49
  82. package/src/data/polish.json +0 -57
  83. package/src/data/portuguese.json +0 -78
  84. package/src/data/russian.json +0 -156
  85. package/src/data/spanish.json +0 -72
  86. package/src/data/swedish.json +0 -47
  87. package/src/data/thai.json +0 -35
  88. package/src/data/turkish.json +0 -195
  89. package/src/filters/Filter.ts +0 -102
  90. package/src/hooks/useProfanityChecker.ts +0 -44
  91. package/src/index.d.ts +0 -36
  92. package/src/index.tsx +0 -10
  93. package/src/types/types.ts +0 -30
  94. package/tsconfig.json +0 -27
  95. package/webpack.config.js +0 -37
@@ -1,102 +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
- ignoreWords?: string[];
13
- logProfanity?: boolean;
14
- }
15
-
16
- class Filter {
17
- private words: Map<string, number>;
18
- private caseSensitive: boolean;
19
- private wordBoundaries: boolean;
20
- private replaceWith?: string;
21
- private severityLevels: boolean;
22
- private ignoreWords: Set<string>;
23
- private logProfanity: boolean;
24
-
25
- constructor(config?: FilterConfig) {
26
- let words: string[] = [];
27
- this.caseSensitive = config?.caseSensitive ?? false;
28
- this.wordBoundaries = config?.wordBoundaries ?? true;
29
- this.replaceWith = config?.replaceWith;
30
- this.severityLevels = config?.severityLevels ?? false;
31
- this.ignoreWords = new Set(config?.ignoreWords?.map(word => word.toLowerCase()) || []);
32
- this.logProfanity = config?.logProfanity ?? false;
33
-
34
- if (config?.allLanguages) {
35
- for (const lang in dictionary) {
36
- if (dictionary.hasOwnProperty(lang)) {
37
- words = [...words, ...dictionary[lang as Language]];
38
- }
39
- }
40
- } else {
41
- const languages = config?.languages || ['english'];
42
- const languagesChecks = new Set<Language>(languages);
43
- if (languagesChecks.size !== 0) {
44
- languagesChecks.forEach(lang => {
45
- words = [...words, ...dictionary[lang]];
46
- });
47
- }
48
- }
49
-
50
- if (config?.customWords) {
51
- words = [...words, ...config.customWords];
52
- }
53
-
54
- this.words = new Map(words.map(word => [word, 1])); // Default severity level is 1
55
- }
56
-
57
- private getRegex(word: string): RegExp {
58
- const flags = this.caseSensitive ? 'g' : 'gi';
59
- const boundary = this.wordBoundaries ? '\\b' : '';
60
- return new RegExp(`${boundary}${word.replace(/(\W)/g, '\\$1')}${boundary}`, flags);
61
- }
62
-
63
- isProfane(value: string): boolean {
64
- for (const word of this.words.keys()) {
65
- if (!this.ignoreWords.has(word.toLowerCase()) && this.getRegex(word).test(value)) return true;
66
- }
67
- return false;
68
- }
69
-
70
- checkProfanity(text: string): CheckProfanityResult {
71
- const words = text.split(/\s+/);
72
- const profaneWords: string[] = [];
73
- const severityMap: { [word: string]: number } = {};
74
-
75
- for (const word of words) {
76
- if (this.words.has(word.toLowerCase()) && !this.ignoreWords.has(word.toLowerCase())) {
77
- profaneWords.push(word);
78
- severityMap[word] = this.words.get(word.toLowerCase())!;
79
- }
80
- }
81
-
82
- if (this.logProfanity && profaneWords.length > 0) {
83
- console.log(`Profane words detected: ${profaneWords.join(', ')}`);
84
- }
85
-
86
- let processedText = text;
87
- if (this.replaceWith) {
88
- for (const word of profaneWords) {
89
- processedText = processedText.replace(this.getRegex(word), this.replaceWith);
90
- }
91
- }
92
-
93
- return {
94
- containsProfanity: profaneWords.length > 0,
95
- profaneWords,
96
- processedText: this.replaceWith ? processedText : undefined,
97
- severityMap: this.severityLevels ? severityMap : undefined,
98
- };
99
- }
100
- }
101
-
102
- 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.d.ts DELETED
@@ -1,36 +0,0 @@
1
- declare module 'glin-profanity' {
2
- export type Language = 'english' | 'french' | 'spanish' | 'german' | 'italian' | 'portuguese' | 'russian' | 'japanese' | 'chinese' | 'korean';
3
-
4
- export interface CheckProfanityResult {
5
- containsProfanity: boolean;
6
- profaneWords: string[];
7
- processedText?: string;
8
- severityMap?: { [word: string]: number };
9
- }
10
-
11
- export interface ProfanityCheckerConfig {
12
- languages?: Language[];
13
- allLanguages?: boolean;
14
- caseSensitive?: boolean;
15
- wordBoundaries?: boolean;
16
- customWords?: string[];
17
- replaceWith?: string;
18
- severityLevels?: boolean;
19
- ignoreWords?: string[];
20
- logProfanity?: boolean;
21
- customActions?: (result: CheckProfanityResult) => void;
22
- }
23
-
24
- export class Filter {
25
- constructor(config?: ProfanityCheckerConfig);
26
- isProfane(value: string): boolean;
27
- checkProfanity(text: string): CheckProfanityResult;
28
- }
29
-
30
- export function useProfanityChecker(config?: ProfanityCheckerConfig): {
31
- result: CheckProfanityResult | null;
32
- checkText: (text: string) => void;
33
- checkTextAsync: (text: string) => Promise<CheckProfanityResult>;
34
- };
35
- }
36
-
package/src/index.tsx DELETED
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import App from './App';
4
-
5
- ReactDOM.render(
6
- <React.StrictMode>
7
- <App />
8
- </React.StrictMode>,
9
- document.getElementById('root')
10
- );
@@ -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
- };