glin-profanity 2.0.0 → 2.3.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 (124) hide show
  1. package/README.md +338 -74
  2. package/lib/cjs/packages/js/src/core/index.d.ts +4 -0
  3. package/lib/cjs/packages/js/src/core/index.js +55 -0
  4. package/lib/cjs/packages/js/src/core/index.js.map +1 -0
  5. package/lib/cjs/packages/js/src/core/types.d.ts +20 -0
  6. package/lib/cjs/packages/js/src/core/types.js +3 -0
  7. package/lib/cjs/packages/js/src/core/types.js.map +1 -0
  8. package/lib/cjs/{data → packages/js/src/data}/dictionary.d.ts +1 -0
  9. package/lib/cjs/packages/js/src/data/dictionary.js +54 -0
  10. package/lib/cjs/packages/js/src/data/dictionary.js.map +1 -0
  11. package/lib/cjs/{filters → packages/js/src/filters}/Filter.d.ts +13 -14
  12. package/lib/cjs/packages/js/src/filters/Filter.js +246 -0
  13. package/lib/cjs/packages/js/src/filters/Filter.js.map +1 -0
  14. package/lib/cjs/packages/js/src/hooks/useProfanityChecker.d.ts +11 -0
  15. package/lib/cjs/packages/js/src/hooks/useProfanityChecker.js +42 -0
  16. package/lib/cjs/packages/js/src/hooks/useProfanityChecker.js.map +1 -0
  17. package/lib/cjs/packages/js/src/index.d.ts +12 -0
  18. package/lib/cjs/packages/js/src/index.js +24 -0
  19. package/lib/cjs/packages/js/src/index.js.map +1 -0
  20. package/lib/cjs/packages/js/src/nlp/contextAnalyzer.d.ts +35 -0
  21. package/lib/cjs/packages/js/src/nlp/contextAnalyzer.js +203 -0
  22. package/lib/cjs/packages/js/src/nlp/contextAnalyzer.js.map +1 -0
  23. package/lib/cjs/packages/js/src/types/types.d.ts +56 -0
  24. package/lib/cjs/packages/js/src/types/types.js +14 -0
  25. package/lib/cjs/packages/js/src/types/types.js.map +1 -0
  26. package/lib/cjs/shared/dictionaries/spanish.json +72 -0
  27. package/lib/esm/packages/js/src/core/index.d.ts +4 -0
  28. package/lib/esm/packages/js/src/core/index.js +47 -0
  29. package/lib/esm/packages/js/src/core/index.js.map +1 -0
  30. package/lib/esm/packages/js/src/core/types.d.ts +20 -0
  31. package/lib/esm/packages/js/src/core/types.js +2 -0
  32. package/lib/esm/packages/js/src/core/types.js.map +1 -0
  33. package/lib/esm/{data → packages/js/src/data}/dictionary.d.ts +1 -0
  34. package/lib/esm/packages/js/src/data/dictionary.js +49 -0
  35. package/lib/esm/packages/js/src/data/dictionary.js.map +1 -0
  36. package/lib/esm/{filters → packages/js/src/filters}/Filter.d.ts +13 -14
  37. package/lib/esm/packages/js/src/filters/Filter.js +240 -0
  38. package/lib/esm/packages/js/src/filters/Filter.js.map +1 -0
  39. package/lib/esm/packages/js/src/hooks/useProfanityChecker.d.ts +11 -0
  40. package/lib/esm/packages/js/src/hooks/useProfanityChecker.js +38 -0
  41. package/lib/esm/packages/js/src/hooks/useProfanityChecker.js.map +1 -0
  42. package/lib/esm/packages/js/src/index.d.ts +12 -0
  43. package/lib/esm/packages/js/src/index.js +15 -0
  44. package/lib/esm/packages/js/src/index.js.map +1 -0
  45. package/lib/esm/packages/js/src/nlp/contextAnalyzer.d.ts +35 -0
  46. package/lib/esm/packages/js/src/nlp/contextAnalyzer.js +199 -0
  47. package/lib/esm/packages/js/src/nlp/contextAnalyzer.js.map +1 -0
  48. package/lib/esm/packages/js/src/types/types.d.ts +56 -0
  49. package/lib/esm/packages/js/src/types/types.js +11 -0
  50. package/lib/esm/packages/js/src/types/types.js.map +1 -0
  51. package/lib/esm/shared/dictionaries/spanish.json +72 -0
  52. package/package.json +26 -3
  53. package/lib/cjs/data/dictionary.js +0 -52
  54. package/lib/cjs/data/dictionary.js.map +0 -1
  55. package/lib/cjs/filters/Filter.js +0 -137
  56. package/lib/cjs/filters/Filter.js.map +0 -1
  57. package/lib/cjs/hooks/useProfanityChecker.d.ts +0 -20
  58. package/lib/cjs/hooks/useProfanityChecker.js +0 -58
  59. package/lib/cjs/hooks/useProfanityChecker.js.map +0 -1
  60. package/lib/cjs/index.d.ts +0 -3
  61. package/lib/cjs/index.js +0 -8
  62. package/lib/cjs/index.js.map +0 -1
  63. package/lib/cjs/types/types.d.ts +0 -14
  64. package/lib/cjs/types/types.js +0 -11
  65. package/lib/cjs/types/types.js.map +0 -1
  66. package/lib/esm/data/dictionary.js +0 -47
  67. package/lib/esm/data/dictionary.js.map +0 -1
  68. package/lib/esm/filters/Filter.js +0 -131
  69. package/lib/esm/filters/Filter.js.map +0 -1
  70. package/lib/esm/hooks/useProfanityChecker.d.ts +0 -20
  71. package/lib/esm/hooks/useProfanityChecker.js +0 -51
  72. package/lib/esm/hooks/useProfanityChecker.js.map +0 -1
  73. package/lib/esm/index.d.ts +0 -3
  74. package/lib/esm/index.js +0 -3
  75. package/lib/esm/index.js.map +0 -1
  76. package/lib/esm/types/types.d.ts +0 -14
  77. package/lib/esm/types/types.js +0 -8
  78. package/lib/esm/types/types.js.map +0 -1
  79. /package/lib/cjs/{data → shared/dictionaries}/Norwegian.json +0 -0
  80. /package/lib/cjs/{data → shared/dictionaries}/arabic.json +0 -0
  81. /package/lib/cjs/{data → shared/dictionaries}/chinese.json +0 -0
  82. /package/lib/cjs/{data → shared/dictionaries}/czech.json +0 -0
  83. /package/lib/cjs/{data → shared/dictionaries}/danish.json +0 -0
  84. /package/lib/cjs/{data → shared/dictionaries}/english.json +0 -0
  85. /package/lib/cjs/{data → shared/dictionaries}/esperanto.json +0 -0
  86. /package/lib/cjs/{data → shared/dictionaries}/finnish.json +0 -0
  87. /package/lib/cjs/{data → shared/dictionaries}/french.json +0 -0
  88. /package/lib/cjs/{data → shared/dictionaries}/german.json +0 -0
  89. /package/lib/cjs/{data → shared/dictionaries}/globalWhitelist.json +0 -0
  90. /package/lib/cjs/{data → shared/dictionaries}/hindi.json +0 -0
  91. /package/lib/cjs/{data → shared/dictionaries}/hungarian.json +0 -0
  92. /package/lib/cjs/{data → shared/dictionaries}/italian.json +0 -0
  93. /package/lib/cjs/{data → shared/dictionaries}/japanese.json +0 -0
  94. /package/lib/cjs/{data → shared/dictionaries}/korean.json +0 -0
  95. /package/lib/cjs/{data → shared/dictionaries}/persian.json +0 -0
  96. /package/lib/cjs/{data → shared/dictionaries}/polish.json +0 -0
  97. /package/lib/cjs/{data → shared/dictionaries}/portuguese.json +0 -0
  98. /package/lib/cjs/{data → shared/dictionaries}/russian.json +0 -0
  99. /package/lib/cjs/{data → shared/dictionaries}/swedish.json +0 -0
  100. /package/lib/cjs/{data → shared/dictionaries}/thai.json +0 -0
  101. /package/lib/cjs/{data → shared/dictionaries}/turkish.json +0 -0
  102. /package/lib/esm/{data → shared/dictionaries}/Norwegian.json +0 -0
  103. /package/lib/esm/{data → shared/dictionaries}/arabic.json +0 -0
  104. /package/lib/esm/{data → shared/dictionaries}/chinese.json +0 -0
  105. /package/lib/esm/{data → shared/dictionaries}/czech.json +0 -0
  106. /package/lib/esm/{data → shared/dictionaries}/danish.json +0 -0
  107. /package/lib/esm/{data → shared/dictionaries}/english.json +0 -0
  108. /package/lib/esm/{data → shared/dictionaries}/esperanto.json +0 -0
  109. /package/lib/esm/{data → shared/dictionaries}/finnish.json +0 -0
  110. /package/lib/esm/{data → shared/dictionaries}/french.json +0 -0
  111. /package/lib/esm/{data → shared/dictionaries}/german.json +0 -0
  112. /package/lib/esm/{data → shared/dictionaries}/globalWhitelist.json +0 -0
  113. /package/lib/esm/{data → shared/dictionaries}/hindi.json +0 -0
  114. /package/lib/esm/{data → shared/dictionaries}/hungarian.json +0 -0
  115. /package/lib/esm/{data → shared/dictionaries}/italian.json +0 -0
  116. /package/lib/esm/{data → shared/dictionaries}/japanese.json +0 -0
  117. /package/lib/esm/{data → shared/dictionaries}/korean.json +0 -0
  118. /package/lib/esm/{data → shared/dictionaries}/persian.json +0 -0
  119. /package/lib/esm/{data → shared/dictionaries}/polish.json +0 -0
  120. /package/lib/esm/{data → shared/dictionaries}/portuguese.json +0 -0
  121. /package/lib/esm/{data → shared/dictionaries}/russian.json +0 -0
  122. /package/lib/esm/{data → shared/dictionaries}/swedish.json +0 -0
  123. /package/lib/esm/{data → shared/dictionaries}/thai.json +0 -0
  124. /package/lib/esm/{data → shared/dictionaries}/turkish.json +0 -0
package/README.md CHANGED
@@ -1,9 +1,122 @@
1
-
2
- # Glin Profanity
3
- Glin-Profanity is a lightweight and efficient npm package designed to detect and filter profane language in text inputs across multiple languages. Whether you’re building a chat application, a comment section, or any platform where user-generated content is involved, Glin-Profanity helps you maintain a clean and respectful environment.
1
+ <p align="center">
2
+ <a href="https://www.glincker.com/tools/glin-profanity" target="_blank">
3
+ <img src="../../assets/glinr-logo.png" alt="Glin Profanity" width="40" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">GLIN PROFANITY</h1>
8
+
9
+ <p align="center">
10
+ <strong>A multilingual profanity detection and filtering engine for modern applications — by <a href="https://glincker.com">GLINCKER</a></strong>
11
+ </p>
12
+ <p align="center">
13
+ <a href="https://www.glincker.com/tools/glin-profanity">
14
+ <img src="https://img.shields.io/badge/🚀%20Try%20Live%20Demo-online-blue" alt="Try Live Demo" />
15
+ </a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://www.npmjs.com/package/glin-profanity">
20
+ <img src="https://img.shields.io/npm/v/glin-profanity" alt="NPM Version" />
21
+ </a>
22
+ <a href="https://github.com/GLINCKER/glin-profanity/blob/main/LICENSE">
23
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License" />
24
+ </a>
25
+ <a href="https://github.com/GLINCKER/glin-profanity/actions">
26
+ <img src="https://img.shields.io/github/actions/workflow/status/GLINCKER/glin-profanity/ci.yml" alt="CI Status" />
27
+ </a>
28
+ <a href="https://www.npmjs.com/package/glin-profanity">
29
+ <img src="https://img.shields.io/npm/dw/glin-profanity" alt="Weekly Downloads" />
30
+ </a>
31
+ <a href="https://github.com/GLINCKER/glin-profanity/issues">
32
+ <img src="https://img.shields.io/github/issues/GLINCKER/glin-profanity" alt="Open Issues" />
33
+ </a>
34
+ <a href="https://github.com/GLINCKER/glin-profanity/pulls">
35
+ <img src="https://img.shields.io/github/issues-pr/GLINCKER/glin-profanity" alt="Open PRs" />
36
+ </a>
37
+ <a href="https://github.com/GLINCKER/glin-profanity/commits/main">
38
+ <img src="https://img.shields.io/github/last-commit/GLINCKER/glin-profanity" alt="Last Commit" />
39
+ </a>
40
+ <a href="https://github.com/GLINCKER/glin-profanity/stargazers">
41
+ <img src="https://img.shields.io/github/stars/GLINCKER/glin-profanity" alt="GitHub Stars" />
42
+ </a>
43
+ <a href="https://github.com/GLINCKER/glin-profanity/network/members">
44
+ <img src="https://img.shields.io/github/forks/GLINCKER/glin-profanity" alt="GitHub Forks" />
45
+ </a>
46
+ <a href="https://github.com/GLINCKER/glin-profanity/graphs/contributors">
47
+ <img src="https://img.shields.io/github/contributors/GLINCKER/glin-profanity" alt="Contributors" />
48
+ </a>
49
+ <a href="#-table-of-contents">
50
+ <img src="https://img.shields.io/badge/-Table%20of%20Contents-blue" alt="Table Of Contents" />
51
+ </a>
52
+ </p>
53
+
54
+ ---
55
+
56
+
57
+ > A multilingual profanity detection and filtering engine for modern applications — by [GLINCKER](https://glincker.com)
58
+
59
+ [![Glin Profanity Preview](../../assets/glin-profanity-preview.png)](https://www.glincker.com/tools/glin-profanity)
60
+
61
+ ---
62
+
63
+ ## ✨ Overview
64
+
65
+ **Glin-Profanity** is a high-performance JavaScript/TypeScript library built to detect, filter, and sanitize profane or harmful language in user-generated content. With support for over 20+ languages, configurable severity levels, obfuscation detection, and framework-agnostic design, it's perfect for developers who care about building safe, inclusive platforms.
66
+
67
+ Whether you're moderating chat messages, community forums, or content input forms, Glin-Profanity empowers you to:
68
+
69
+ - 🧼 Filter text with real-time or batch processing
70
+ - 🗣️ Detect offensive terms in **20+ human languages**
71
+ - 💬 Catch obfuscated profanity like `sh1t`, `f*ck`, `a$$hole`
72
+ - 🎚️ Adjust severity thresholds (`Exact`, `Fuzzy`, `Merged`)
73
+ - 🔁 Replace bad words with symbols or emojis
74
+ - 🧩 Works in **any JavaScript environment** - <img src="https://img.shields.io/badge/Node.js-339933?style=flat&logo=nodedotjs&logoColor=white" alt="Node.js" height="16" /> <img src="https://img.shields.io/badge/React-20232A?style=flat&logo=react&logoColor=61DAFB" alt="React" height="16" /> <img src="https://img.shields.io/badge/Vue-35495E?style=flat&logo=vuedotjs&logoColor=4FC08D" alt="Vue" height="16" /> <img src="https://img.shields.io/badge/Angular-DD0031?style=flat&logo=angular&logoColor=white" alt="Angular" height="16" /> <img src="https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white" alt="TypeScript" height="16" />
75
+ - 🛡️ Add custom word lists or ignore specific terms
76
+
77
+ ## 🚀 Key Features
78
+
79
+ <div align="center">
80
+ <img src="https://img.shields.io/badge/Multi--Language-🌍-blue?style=for-the-badge" alt="Multi-Language" />
81
+ <img src="https://img.shields.io/badge/Real--Time-⚡-yellow?style=for-the-badge" alt="Real-Time" />
82
+ <img src="https://img.shields.io/badge/Obfuscation_Detection-🕵️-purple?style=for-the-badge" alt="Obfuscation" />
83
+ <img src="https://img.shields.io/badge/Framework_Agnostic-🧩-green?style=for-the-badge" alt="Framework Agnostic" />
84
+ </div>
85
+
86
+ ## 📚 Table of Contents
87
+
88
+ - [🚀 Key Features](#-key-features)
89
+ - [📦 Installation](#installation)
90
+ - [🌍 Supported Languages](#supported-languages)
91
+ - [⚙️ Usage](#usage)
92
+ - [Basic Usage](#basic-usage)
93
+ - [Framework Examples](#framework-examples)
94
+ - [🧠 API](#api)
95
+ - [Core Functions](#core-functions)
96
+ - [Filter Class](#filter-class)
97
+ - [Constructor](#constructor)
98
+ - [FilterConfig Options](#filterconfig-options)
99
+ - [Methods](#methods)
100
+ - [isProfane](#isprofane)
101
+ - [checkProfanity](#checkprofanity)
102
+ - [useProfanityChecker Hook](#useprofanitychecker-hook)
103
+ - [Parameters](#parameters)
104
+ - [Return Value](#return-value)
105
+ - [⚠️ Note](#note)
106
+ - [🛠 Use Cases](#-use-cases)
107
+ - [📄 License](#license)
108
+ - [MIT License](#mit-license)
4
109
 
5
110
  ## Installation
6
111
 
112
+ <div align="center">
113
+ <img src="https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white" alt="npm" />
114
+ <img src="https://img.shields.io/badge/Yarn-2C8EBB?style=for-the-badge&logo=yarn&logoColor=white" alt="yarn" />
115
+ <img src="https://img.shields.io/badge/pnpm-F69220?style=for-the-badge&logo=pnpm&logoColor=white" alt="pnpm" />
116
+ </div>
117
+
118
+ <br />
119
+
7
120
  To install Glin-Profanity, use npm:
8
121
 
9
122
  ```bash
@@ -14,91 +127,238 @@ OR
14
127
  ```bash
15
128
  yarn add glin-profanity
16
129
  ```
130
+ OR
131
+
132
+ ```bash
133
+ pnpm add glin-profanity
134
+ ```
135
+
136
+ ## Supported Languages
137
+
138
+ Glin-Profanity includes comprehensive profanity dictionaries for **23 languages**:
139
+
140
+ 🇸🇦 **Arabic** • 🇨🇳 **Chinese** • 🇨🇿 **Czech** • 🇩🇰 **Danish** • 🇬🇧 **English** • 🌍 **Esperanto** • 🇫🇮 **Finnish** • 🇫🇷 **French** • 🇩🇪 **German** • 🇮🇳 **Hindi** • 🇭🇺 **Hungarian** • 🇮🇹 **Italian** • 🇯🇵 **Japanese** • 🇰🇷 **Korean** • 🇳🇴 **Norwegian** • 🇮🇷 **Persian** • 🇵🇱 **Polish** • 🇵🇹 **Portuguese** • 🇷🇺 **Russian** • 🇪🇸 **Spanish** • 🇸🇪 **Swedish** • 🇹🇭 **Thai** • 🇹🇷 **Turkish**
141
+
142
+ > **Note**: The JavaScript and Python packages maintain cross-language parity, ensuring consistent profanity detection across both ecosystems.
143
+
17
144
  ## Usage
18
145
 
19
146
  ### Basic Usage
20
147
 
21
- Here's a simple example of how to use Glin-Profanity in a React application:
148
+ Glin-Profanity now provides framework-agnostic core functions alongside React-specific hooks:
149
+
150
+ #### 🟢 Node.js / Vanilla JavaScript
151
+
152
+ ```javascript
153
+ const { checkProfanity } = require('glin-profanity');
154
+
155
+ const text = "This is some bad text with damn words";
156
+ const result = checkProfanity(text, {
157
+ languages: ['english', 'spanish'],
158
+ replaceWith: '***'
159
+ });
160
+
161
+ console.log(result.containsProfanity); // true
162
+ console.log(result.profaneWords); // ['damn']
163
+ console.log(result.processedText); // "This is some bad text with *** words"
164
+ ```
165
+
166
+ #### 🔷 TypeScript
22
167
 
23
168
  ```typescript
24
- import React, { useState } from 'react';
25
- import { useProfanityChecker, Language } from 'glin-profanity';
169
+ import { checkProfanity, ProfanityCheckerConfig } from 'glin-profanity';
26
170
 
27
- const App: React.FC = () => {
28
- const [text, setText] = useState('');
29
- const [checkAllLanguages, setCheckAllLanguages] = useState(false);
30
- const { result, checkText } = useProfanityChecker(
31
- checkAllLanguages ? { allLanguages: true } : { languages: ['english', 'french'] }
32
- );
171
+ const config: ProfanityCheckerConfig = {
172
+ languages: ['english', 'spanish'],
173
+ severityLevels: true,
174
+ autoReplace: true,
175
+ replaceWith: '🤬'
176
+ };
177
+
178
+ const result = checkProfanity("inappropriate text", config);
179
+ ```
33
180
 
34
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
35
- setText(e.target.value);
36
- };
181
+ ### Framework Examples
37
182
 
38
- const handleCheck = () => {
39
- checkText(text);
40
- };
183
+ <div align="center">
184
+ <img src="https://img.shields.io/badge/Node.js-339933?style=for-the-badge&logo=nodedotjs&logoColor=white" alt="Node.js" />
185
+ <img src="https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB" alt="React" />
186
+ <img src="https://img.shields.io/badge/Vue.js-35495E?style=for-the-badge&logo=vuedotjs&logoColor=4FC08D" alt="Vue.js" />
187
+ <img src="https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white" alt="Angular" />
188
+ <img src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript" />
189
+ </div>
190
+
191
+ #### ⚛️ React
192
+
193
+ ```tsx
194
+ import React, { useState } from 'react';
195
+ import { useProfanityChecker, SeverityLevel } from 'glin-profanity';
196
+
197
+ const App = () => {
198
+ const [text, setText] = useState('');
199
+
200
+ const { result, checkText } = useProfanityChecker({
201
+ languages: ['english', 'spanish'],
202
+ severityLevels: true,
203
+ autoReplace: true,
204
+ replaceWith: '***',
205
+ minSeverity: SeverityLevel.EXACT
206
+ });
41
207
 
42
208
  return (
43
209
  <div>
44
- <h1>Welcome to Glin-Profanity</h1>
45
- <input type="text" value={text} onChange={handleChange} />
46
- <button onClick={handleCheck}>Check Profanity</button>
47
- <div>
48
- <label>
49
- <input
50
- type="checkbox"
51
- checked={checkAllLanguages}
52
- onChange={(e) => setCheckAllLanguages(e.target.checked)}
53
- />
54
- Check All Languages
55
- </label>
56
- </div>
57
- {result && (
58
- <div>
59
- <p>Contains Profanity: {result.containsProfanity ? 'Yes' : 'No'}</p>
60
- {result.containsProfanity && (
61
- <p>Profane Words: {result.profaneWords.join(', ')}</p>
62
- )}
63
- </div>
210
+ <input value={text} onChange={(e) => setText(e.target.value)} />
211
+ <button onClick={() => checkText(text)}>Scan</button>
212
+
213
+ {result && result.containsProfanity && (
214
+ <p>Cleaned: {result.processedText}</p>
64
215
  )}
65
216
  </div>
66
217
  );
67
218
  };
219
+ ```
220
+
221
+ #### 💚 Vue 3
222
+
223
+ ```vue
224
+ <template>
225
+ <div>
226
+ <input v-model="text" @input="checkContent" />
227
+ <p v-if="hasProfanity">{{ cleanedText }}</p>
228
+ </div>
229
+ </template>
230
+
231
+ <script setup>
232
+ import { ref } from 'vue';
233
+ import { checkProfanity } from 'glin-profanity';
234
+
235
+ const text = ref('');
236
+ const hasProfanity = ref(false);
237
+ const cleanedText = ref('');
238
+
239
+ const checkContent = () => {
240
+ const result = checkProfanity(text.value, {
241
+ languages: ['english'],
242
+ autoReplace: true,
243
+ replaceWith: '***'
244
+ });
245
+
246
+ hasProfanity.value = result.containsProfanity;
247
+ cleanedText.value = result.autoReplaced;
248
+ };
249
+ </script>
250
+ ```
251
+
252
+ #### 🔴 Angular
253
+
254
+ ```typescript
255
+ import { Component } from '@angular/core';
256
+ import { checkProfanity, ProfanityCheckResult } from 'glin-profanity';
257
+
258
+ @Component({
259
+ selector: 'app-comment',
260
+ template: `
261
+ <textarea [(ngModel)]="comment" (ngModelChange)="validateComment()"></textarea>
262
+ <div *ngIf="profanityResult?.containsProfanity" class="error">
263
+ Please remove inappropriate language
264
+ </div>
265
+ `
266
+ })
267
+ export class CommentComponent {
268
+ comment = '';
269
+ profanityResult: ProfanityCheckResult | null = null;
270
+
271
+ validateComment() {
272
+ this.profanityResult = checkProfanity(this.comment, {
273
+ languages: ['english', 'spanish'],
274
+ severityLevels: true
275
+ });
276
+ }
277
+ }
278
+ ```
279
+
280
+ #### 🚂 Express.js Middleware
281
+
282
+ ```javascript
283
+ const express = require('express');
284
+ const { checkProfanity } = require('glin-profanity');
285
+
286
+ const profanityMiddleware = (req, res, next) => {
287
+ const result = checkProfanity(req.body.message || '', {
288
+ languages: ['english'],
289
+ autoReplace: true,
290
+ replaceWith: '[censored]'
291
+ });
292
+
293
+ if (result.containsProfanity) {
294
+ req.body.message = result.autoReplaced;
295
+ }
296
+
297
+ next();
298
+ };
68
299
 
69
- export default App;
300
+ app.post('/comment', profanityMiddleware, (req, res) => {
301
+ // Message is now sanitized
302
+ res.json({ message: req.body.message });
303
+ });
70
304
  ```
71
305
 
72
306
  ## API
73
307
 
74
- ### `Filter` Class
308
+ ### 🎯 Core Functions
309
+
310
+ #### `checkProfanity`
311
+
312
+ Framework-agnostic function for profanity detection.
313
+
314
+ ```typescript
315
+ checkProfanity(text: string, config?: ProfanityCheckerConfig): ProfanityCheckResult
316
+ ```
317
+
318
+ #### `checkProfanityAsync`
319
+
320
+ Async version of checkProfanity.
321
+
322
+ ```typescript
323
+ checkProfanityAsync(text: string, config?: ProfanityCheckerConfig): Promise<ProfanityCheckResult>
324
+ ```
325
+
326
+ #### `isWordProfane`
327
+
328
+ Quick check if a single word is profane.
329
+
330
+ ```typescript
331
+ isWordProfane(word: string, config?: ProfanityCheckerConfig): boolean
332
+ ```
333
+
334
+ ### 🔧 `Filter` Class
75
335
 
76
336
  #### Constructor
77
337
 
78
338
  ```typescript
79
- new Filter(config?: {
80
- languages?: Language[];
81
- allLanguages?: boolean;
82
- caseSensitive?: boolean;
83
- wordBoundaries?: boolean;
84
- customWords?: string[];
85
- replaceWith?: string;
86
- severityLevels?: boolean;
87
- ignoreWords?: string[];
88
- logProfanity?: boolean;
89
- });
339
+ new Filter(config?: FilterConfig);
90
340
  ```
91
341
 
92
- - `config`: An optional configuration object.
93
- - `languages`: An array of languages to check for profanities.
94
- - `allLanguages`: A boolean indicating whether to check for all languages.
95
- - `caseSensitive`: A boolean indicating whether the profanity check should be case-sensitive.
96
- - `wordBoundaries`: A boolean indicating whether to consider word boundaries when checking for profanities.
97
- - `customWords`: An array of custom words to include in the profanity check.
98
- - `replaceWith`: A string to replace profane words with.
99
- - `severityLevels`: A boolean indicating whether to include severity levels for profane words.
100
- - `ignoreWords`: An array of words to ignore in the profanity check.
101
- - `logProfanity`: A boolean indicating whether to log detected profane words.
342
+ #### FilterConfig Options:
343
+
344
+ | Option | Type | Description |
345
+ |-------------------------|--------------------|-------------|
346
+ | `languages` | `Language[]` | Languages to include (e.g., ['english', 'spanish']) |
347
+ | `allLanguages` | `boolean` | If true, scan all available languages |
348
+ | `caseSensitive` | `boolean` | Match case exactly |
349
+ | `wordBoundaries` | `boolean` | Only match full words (turn off for substring matching) |
350
+ | `customWords` | `string[]` | Add your own words |
351
+ | `replaceWith` | `string` | Replace matched words with this string |
352
+ | `severityLevels` | `boolean` | Enable severity mapping (Exact, Fuzzy, Merged) |
353
+ | `ignoreWords` | `string[]` | Words to skip even if found |
354
+ | `logProfanity` | `boolean` | Log results via console |
355
+ | `allowObfuscatedMatch` | `boolean` | Enable fuzzy pattern matching like `f*ck` |
356
+ | `fuzzyToleranceLevel` | `number (0–1)` | Adjust how tolerant fuzzy matching is |
357
+ | `autoReplace` | `boolean` | Whether to auto-replace flagged words |
358
+ | `minSeverity` | `SeverityLevel` | Minimum severity to include in final list |
359
+ | `customActions` | `(result) => void` | Custom logging/callback support |
360
+
361
+ ---
102
362
 
103
363
  #### Methods
104
364
 
@@ -128,34 +388,38 @@ checkProfanity(text: string): CheckProfanityResult;
128
388
  - `processedText`: `string` - The text with profane words replaced (if `replaceWith` is specified).
129
389
  - `severityMap`: `{ [word: string]: number }` - A map of profane words to their severity levels (if `severityLevels` is specified).
130
390
 
131
- ### `useProfanityChecker` Hook
391
+ ### ⚛️ `useProfanityChecker` Hook
132
392
 
133
393
  A custom React hook for using the profanity checker.
134
394
 
135
395
  #### Parameters
136
396
 
137
- - `config`: An optional configuration object.
138
- - `languages`: An array of languages to check for profanities.
139
- - `allLanguages`: A boolean indicating whether to check for all languages.
140
- - `caseSensitive`: A boolean indicating whether the profanity check should be case-sensitive.
141
- - `wordBoundaries`: A boolean indicating whether to consider word boundaries when checking for profanities.
142
- - `customWords`: An array of custom words to include in the profanity check.
143
- - `replaceWith`: A string to replace profane words with.
144
- - `severityLevels`: A boolean indicating whether to include severity levels for profane words.
145
- - `ignoreWords`: An array of words to ignore in the profanity check.
146
- - `logProfanity`: A boolean indicating whether to log detected profane words.
147
- - `customActions`: A function to execute custom actions when profanity is detected.
397
+ - `config`: An optional configuration object (same as ProfanityCheckerConfig).
148
398
 
149
399
  #### Return Value
150
400
 
151
401
  - `result`: The result of the profanity check.
152
402
  - `checkText`: A function to check a given text for profanities.
153
403
  - `checkTextAsync`: A function to check a given text for profanities asynchronously.
404
+ - `reset`: A function to reset the result state.
405
+ - `isDirty`: Boolean indicating if profanity was found.
406
+ - `isWordProfane`: Function to check if a single word is profane.
154
407
 
155
408
  ```typescript
156
- const { result, checkText, checkTextAsync } = useProfanityChecker(config);
409
+ const { result, checkText, checkTextAsync, reset, isDirty, isWordProfane } = useProfanityChecker(config);
157
410
  ```
158
411
 
412
+ ## Note
413
+ ⚠️ Glin-Profanity is a best-effort tool. Language evolves, and no filter is perfect. Always supplement with human moderation for high-risk platforms.
414
+
415
+ ## 🛠 Use Cases
416
+
417
+ - 🔐 Chat moderation in messaging apps
418
+ - 🧼 Comment sanitization for blogs or forums
419
+ - 🕹️ Game lobbies & multiplayer chats
420
+ - 🤖 AI content filters before processing input
421
+
422
+
159
423
  ## License
160
424
 
161
425
  This software is also available under the GLINCKER LLC proprietary license. The proprietary license allows for use, modification, and distribution of the software with certain restrictions and conditions as set forth by GLINCKER LLC.
@@ -0,0 +1,4 @@
1
+ import { ProfanityCheckerConfig, ProfanityCheckResult } from './types';
2
+ export declare function checkProfanity(text: string, config?: ProfanityCheckerConfig): ProfanityCheckResult;
3
+ export declare function checkProfanityAsync(text: string, config?: ProfanityCheckerConfig): Promise<ProfanityCheckResult>;
4
+ export declare function isWordProfane(word: string, config?: ProfanityCheckerConfig): boolean;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkProfanity = checkProfanity;
16
+ exports.checkProfanityAsync = checkProfanityAsync;
17
+ exports.isWordProfane = isWordProfane;
18
+ const Filter_1 = require("../filters/Filter");
19
+ const globalWhitelist_json_1 = __importDefault(require("@shared/dictionaries/globalWhitelist.json"));
20
+ function createFilterConfig(config) {
21
+ var _a;
22
+ const effective = Object.assign(Object.assign({}, (config !== null && config !== void 0 ? config : {})), { ignoreWords: globalWhitelist_json_1.default.whitelist, fuzzyToleranceLevel: (_a = config === null || config === void 0 ? void 0 : config.fuzzyToleranceLevel) !== null && _a !== void 0 ? _a : 0.8 });
23
+ if (effective.allowObfuscatedMatch && effective.wordBoundaries) {
24
+ console.warn('[Glin-Profanity] Obfuscated match enabled → wordBoundaries will be ignored internally.');
25
+ }
26
+ return effective;
27
+ }
28
+ function checkProfanity(text, config) {
29
+ var _a;
30
+ const filterConfig = createFilterConfig(config);
31
+ const filter = new Filter_1.Filter(filterConfig);
32
+ const checkResult = filter.checkProfanity(text);
33
+ // Filter based on minSeverity (if provided)
34
+ const filteredWords = (config === null || config === void 0 ? void 0 : config.minSeverity) && checkResult.severityMap
35
+ ? checkResult.profaneWords.filter((word) => checkResult.severityMap &&
36
+ checkResult.severityMap[word] >= config.minSeverity)
37
+ : checkResult.profaneWords;
38
+ // Optional auto-replace
39
+ const autoReplaced = (config === null || config === void 0 ? void 0 : config.autoReplace) && checkResult.processedText
40
+ ? checkResult.processedText
41
+ : text;
42
+ // Custom actions
43
+ (_a = config === null || config === void 0 ? void 0 : config.customActions) === null || _a === void 0 ? void 0 : _a.call(config, checkResult);
44
+ return Object.assign(Object.assign({}, checkResult), { filteredWords,
45
+ autoReplaced });
46
+ }
47
+ function checkProfanityAsync(text, config) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return Promise.resolve(checkProfanity(text, config));
50
+ });
51
+ }
52
+ function isWordProfane(word, config) {
53
+ return checkProfanity(word, config).containsProfanity;
54
+ }
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAoBA,wCA6BC;AAED,kDAEC;AAED,sCAEC;AAzDD,8CAAyD;AAEzD,qGAA4E;AAE5E,SAAS,kBAAkB,CAAC,MAA+B;;IACzD,MAAM,SAAS,mCACV,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,KACjB,WAAW,EAAG,8BAA2B,CAAC,SAAS,EACnD,mBAAmB,EAAE,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,mCAAI,GAAG,GACxD,CAAC;IAEF,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,CAAC,cAAc,EAAE,CAAC;QAC/D,OAAO,CAAC,IAAI,CACV,wFAAwF,CACzF,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAgB,cAAc,CAAC,IAAY,EAAE,MAA+B;;IAC1E,MAAM,YAAY,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,YAAY,CAAC,CAAC;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEhD,4CAA4C;IAC5C,MAAM,aAAa,GACjB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,KAAI,WAAW,CAAC,WAAW;QAC5C,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,MAAM,CAC7B,CAAC,IAAI,EAAE,EAAE,CACP,WAAW,CAAC,WAAW;YACvB,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,WAAY,CACvD;QACH,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC;IAE/B,wBAAwB;IACxB,MAAM,YAAY,GAChB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,KAAI,WAAW,CAAC,aAAa;QAC9C,CAAC,CAAC,WAAW,CAAC,aAAa;QAC3B,CAAC,CAAC,IAAI,CAAC;IAEX,iBAAiB;IACjB,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,uDAAG,WAAW,CAAC,CAAC;IAErC,uCACK,WAAW,KACd,aAAa;QACb,YAAY,IACZ;AACJ,CAAC;AAED,SAAsB,mBAAmB,CAAC,IAAY,EAAE,MAA+B;;QACrF,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;CAAA;AAED,SAAgB,aAAa,CAAC,IAAY,EAAE,MAA+B;IACzE,OAAO,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,iBAAiB,CAAC;AACxD,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { CheckProfanityResult, Language, SeverityLevel } from '../types/types';
2
+ export interface ProfanityCheckerConfig {
3
+ languages?: Language[];
4
+ allLanguages?: boolean;
5
+ caseSensitive?: boolean;
6
+ wordBoundaries?: boolean;
7
+ customWords?: string[];
8
+ replaceWith?: string;
9
+ severityLevels?: boolean;
10
+ allowObfuscatedMatch?: boolean;
11
+ fuzzyToleranceLevel?: number;
12
+ minSeverity?: SeverityLevel;
13
+ autoReplace?: boolean;
14
+ customActions?: (result: CheckProfanityResult) => void;
15
+ }
16
+ export interface ProfanityCheckResult extends CheckProfanityResult {
17
+ filteredWords: string[];
18
+ autoReplaced: string;
19
+ }
20
+ export type { CheckProfanityResult, Language, SeverityLevel, FilterConfig } from '../types/types';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/core/types.ts"],"names":[],"mappings":""}
@@ -18,6 +18,7 @@ declare const _default: {
18
18
  polish: string[];
19
19
  portuguese: string[];
20
20
  russian: string[];
21
+ spanish: string[];
21
22
  turkish: string[];
22
23
  swedish: string[];
23
24
  thai: string[];
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const arabic_json_1 = __importDefault(require("@shared/dictionaries/arabic.json"));
7
+ const chinese_json_1 = __importDefault(require("@shared/dictionaries/chinese.json"));
8
+ const czech_json_1 = __importDefault(require("@shared/dictionaries/czech.json"));
9
+ const danish_json_1 = __importDefault(require("@shared/dictionaries/danish.json"));
10
+ const esperanto_json_1 = __importDefault(require("@shared/dictionaries/esperanto.json"));
11
+ const english_json_1 = __importDefault(require("@shared/dictionaries/english.json"));
12
+ const finnish_json_1 = __importDefault(require("@shared/dictionaries/finnish.json"));
13
+ const german_json_1 = __importDefault(require("@shared/dictionaries/german.json"));
14
+ const hindi_json_1 = __importDefault(require("@shared/dictionaries/hindi.json"));
15
+ const hungarian_json_1 = __importDefault(require("@shared/dictionaries/hungarian.json"));
16
+ const korean_json_1 = __importDefault(require("@shared/dictionaries/korean.json"));
17
+ const Norwegian_json_1 = __importDefault(require("@shared/dictionaries/Norwegian.json"));
18
+ const persian_json_1 = __importDefault(require("@shared/dictionaries/persian.json"));
19
+ const polish_json_1 = __importDefault(require("@shared/dictionaries/polish.json"));
20
+ const portuguese_json_1 = __importDefault(require("@shared/dictionaries/portuguese.json"));
21
+ const russian_json_1 = __importDefault(require("@shared/dictionaries/russian.json"));
22
+ const french_json_1 = __importDefault(require("@shared/dictionaries/french.json"));
23
+ const italian_json_1 = __importDefault(require("@shared/dictionaries/italian.json"));
24
+ const japanese_json_1 = __importDefault(require("@shared/dictionaries/japanese.json"));
25
+ const turkish_json_1 = __importDefault(require("@shared/dictionaries/turkish.json"));
26
+ const spanish_json_1 = __importDefault(require("@shared/dictionaries/spanish.json"));
27
+ const swedish_json_1 = __importDefault(require("@shared/dictionaries/swedish.json"));
28
+ const thai_json_1 = __importDefault(require("@shared/dictionaries/thai.json"));
29
+ exports.default = {
30
+ arabic: arabic_json_1.default.words,
31
+ chinese: chinese_json_1.default.words,
32
+ czech: czech_json_1.default.words,
33
+ danish: danish_json_1.default.words,
34
+ english: english_json_1.default.words,
35
+ esperanto: esperanto_json_1.default.words,
36
+ finnish: finnish_json_1.default.words,
37
+ french: french_json_1.default.words,
38
+ german: german_json_1.default.words,
39
+ hindi: hindi_json_1.default.words,
40
+ hungarian: hungarian_json_1.default.words,
41
+ italian: italian_json_1.default.words,
42
+ japanese: japanese_json_1.default.words,
43
+ korean: korean_json_1.default.words,
44
+ norwegian: Norwegian_json_1.default.words,
45
+ persian: persian_json_1.default.words,
46
+ polish: polish_json_1.default.words,
47
+ portuguese: portuguese_json_1.default.words,
48
+ russian: russian_json_1.default.words,
49
+ spanish: spanish_json_1.default.words,
50
+ turkish: turkish_json_1.default.words,
51
+ swedish: swedish_json_1.default.words,
52
+ thai: thai_json_1.default.words,
53
+ };
54
+ //# sourceMappingURL=dictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../../../../../src/data/dictionary.ts"],"names":[],"mappings":";;;;;AAAA,mFAAsD;AACtD,qFAAwD;AACxD,iFAAoD;AACpD,mFAAsD;AACtD,yFAA4D;AAC5D,qFAAwD;AACxD,qFAAwD;AACxD,mFAAsD;AACtD,iFAAoD;AACpD,yFAA4D;AAC5D,mFAAsD;AACtD,yFAA4D;AAC5D,qFAAwD;AACxD,mFAAsD;AACtD,2FAA8D;AAC9D,qFAAwD;AACxD,mFAAsD;AACtD,qFAAwD;AACxD,uFAA0D;AAC1D,qFAAwD;AACxD,qFAAwD;AACxD,qFAAwD;AACxD,+EAAkD;AAClD,kBAAe;IACb,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,KAAK,EAAE,oBAAK,CAAC,KAAK;IAClB,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,SAAS,EAAE,wBAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,KAAK,EAAE,oBAAK,CAAC,KAAK;IAClB,SAAS,EAAE,wBAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,QAAQ,EAAE,uBAAQ,CAAC,KAAK;IACxB,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,SAAS,EAAE,wBAAS,CAAC,KAAK;IAC1B,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,MAAM,EAAE,qBAAM,CAAC,KAAK;IACpB,UAAU,EAAE,yBAAU,CAAC,KAAK;IAC5B,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,OAAO,EAAE,sBAAO,CAAC,KAAK;IACtB,IAAI,EAAE,mBAAI,CAAC,KAAK;CACjB,CAAC"}