|
1 | 1 |  |
2 | 2 |
|
3 | | -## Description |
4 | 3 |
|
5 | | -Full list of bad words and top swear words banned by Google. The list is updated monthly. Pull requests are welcome! |
6 | 4 |
|
7 | | -The `@coffeeandfun/google-profanity-words` is a Node.js module created by Robert James Gabriel from Coffee & Fun LLC. It is designed to help you identify and manage profanity words in a given text. The module provides functions to retrieve a list of all known profanity words, check if a specific word is considered profane, and handle empty strings appropriately. |
| 5 | +# ☕ Google Profanity Words |
8 | 6 |
|
9 | | -## Installation |
| 7 | +> A fun and developer-friendly profanity detection library brought to you by [Coffee & Fun LLC](https://coffeeandfun.com) ☕🎉 |
| 8 | +> Built and maintained with love by [Robert James Gabriel](https://github.com/robertgabriel) 💻✨ |
10 | 9 |
|
11 | | -You can install the `@coffeeandfun/google-profanity-words` module using npm: |
| 10 | +[](https://www.npmjs.com/package/@coffeeandfun/google-profanity-words) [](https://github.com/@coffeeandfun/google-profanity-words) |
| 11 | + |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 🚀 What’s This? |
| 16 | + |
| 17 | +**Google Profanity Words** is a Node.js library that helps you detect and filter out naughty language (in multiple languages!) from your apps or content. Whether you’re building a chat app, a comment section, or a game—this one’s your profanity-slaying sidekick. |
| 18 | + |
| 19 | +Made by devs for devs. Maintained by Robert at Coffee & Fun ☕❤️ |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## ✨ Features |
| 24 | + |
| 25 | +- 🌐 **Multilingual support** – English and Spanish out of the box. More coming soon! |
| 26 | +- 🔁 **Monthly updates** – Stay fresh with the latest no-no words |
| 27 | +- 💡 **Easy to use API** – Straightforward methods, async/await friendly |
| 28 | +- 🔬 **Tested with Jest** – Fully covered and ready for production |
| 29 | +- ⚡ **Tiny & Fast** – Minimal deps = speedy installs and performance |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 📦 Install Me |
12 | 34 |
|
13 | 35 | ```bash |
14 | 36 | npm install @coffeeandfun/google-profanity-words |
15 | 37 | ``` |
16 | 38 |
|
17 | | -## Usage |
| 39 | +--- |
18 | 40 |
|
19 | | -To use the `@coffeeandfun/google-profanity-words`, first, import the module and create an instance: |
| 41 | +## ⚡ Quickstart Guide |
20 | 42 |
|
21 | 43 | ```javascript |
22 | 44 | import { ProfanityEngine } from '@coffeeandfun/google-profanity-words'; |
23 | 45 |
|
24 | | -// Pass the 'language' parameter to specify the language (optional). |
25 | | -// Defaults to 'en' if no valid language code is provided. |
26 | | -const profanity = new ProfanityEngine({ language: 'es' }); |
| 46 | +// Default is English |
| 47 | +const profanity = new ProfanityEngine(); |
| 48 | + |
| 49 | +// Español? You got it. |
| 50 | +const profanityES = new ProfanityEngine({ language: 'es' }); |
| 51 | + |
| 52 | +// Check a single word |
| 53 | +const isBad = await profanity.search('example'); |
| 54 | + |
| 55 | +// Or check a full sentence |
| 56 | +const hasCurses = await profanity.hasCurseWords('This is a test sentence'); |
| 57 | + |
| 58 | +console.log(isBad, hasCurses); // true / false |
27 | 59 | ``` |
28 | 60 |
|
29 | | -The language parameter is optional and can be used to specify the language for the profanity list. It defaults to 'en' if no valid language code is provided. If the specified language file is not found, it will fall back to the 'en' language file and display a console warning. |
| 61 | +--- |
30 | 62 |
|
31 | | -## API Functions |
| 63 | +## 🔍 API Docs (But Make It Chill) |
32 | 64 |
|
33 | | -### 1. `all()` |
| 65 | +### 🛠️ `new ProfanityEngine(options?)` |
34 | 66 |
|
35 | | -Retrieves all the profanity words as an array. |
| 67 | +Create a new profanity detector engine! |
36 | 68 |
|
37 | 69 | ```javascript |
38 | | -const allWords = await profanity.all(); |
| 70 | +const profanity = new ProfanityEngine(); // Defaults to English |
39 | 71 | ``` |
40 | 72 |
|
41 | | -### 2. `search(word)` |
| 73 | +Or choose a specific language: |
42 | 74 |
|
43 | | -Checks if a given word is considered profane. |
| 75 | +```javascript |
| 76 | +const spanishProfanity = new ProfanityEngine({ language: 'es' }); |
| 77 | +``` |
| 78 | + |
| 79 | +#### Options: |
| 80 | +- `language` (string, optional): |
| 81 | + - `'en'` = English (default) |
| 82 | + - `'es'` = Spanish |
| 83 | + - If a language isn’t available, it falls back to English. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +### 🔎 `search(word)` |
| 88 | + |
| 89 | +Check a single word to see if it's naughty. |
44 | 90 |
|
45 | 91 | ```javascript |
46 | | -const searchWord = await profanity.search('shit'); |
47 | | -// Returns true if the word is profane, otherwise false. |
| 92 | +const isProfane = await profanity.search('heck'); |
| 93 | +console.log(isProfane); // true or false |
48 | 94 | ``` |
49 | 95 |
|
50 | | -### 3. hasCurseWords(sentence) |
| 96 | +--- |
| 97 | + |
| 98 | +### 💬 `hasCurseWords(sentence)` |
51 | 99 |
|
52 | | -Checks if a given sentence contains any profanity words. |
| 100 | +Check a full sentence or phrase for profanity. |
53 | 101 |
|
54 | 102 | ```javascript |
55 | | -const sentence = 'Do not use bad words like mierda or idiota.'; |
56 | | -const hasCurseWords = await profanity.hasCurseWords(sentence); |
57 | | -// Returns true if the sentence contains profanity words, otherwise false. |
| 103 | +const result = await profanity.hasCurseWords('You silly goose'); |
| 104 | +console.log(result); // probably false, unless goose is banned now 🪿 |
58 | 105 | ``` |
59 | 106 |
|
60 | | -### 4. Handling Empty Strings |
| 107 | +--- |
| 108 | + |
| 109 | +### 📜 `all()` |
61 | 110 |
|
62 | | -The `search` and `hasCurseWords` functions will return false for any empty string. |
| 111 | +Get the full list of bad words in the current language. |
63 | 112 |
|
64 | 113 | ```javascript |
65 | | -const searchWord = await profanity.search(''); |
66 | | -const hasCurseWords = await profanity.hasCurseWords(''); |
67 | | -// Returns false for an empty string. |
| 114 | +const badWords = await profanity.all(); |
| 115 | +console.log(badWords); // ['word1', 'word2', 'etc'] |
68 | 116 | ``` |
69 | 117 |
|
70 | | -## Testing |
| 118 | +--- |
| 119 | + |
| 120 | +### 💡 Real Talk: Edge Cases |
| 121 | + |
| 122 | +- Empty strings? We gotchu. Returns `false`. |
| 123 | +- `search()` and `hasCurseWords()` are **case-insensitive**. |
| 124 | +- Special characters and punctuation? No problem. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## 🧪 Testing with Jest |
71 | 129 |
|
72 | | -The `@coffeeandfun/google-profanity-words` comes with a test suite using the Jest framework. To run the tests, use the following command: |
| 130 | +We've got testing covered like whipped cream on a latte ☕🎂 |
| 131 | + |
| 132 | +Run the default test suite: |
73 | 133 |
|
74 | 134 | ```bash |
75 | 135 | npm test |
76 | 136 | ``` |
77 | 137 |
|
78 | | -## Contributing |
| 138 | +Or use more specific Jest commands: |
| 139 | + |
| 140 | +```bash |
| 141 | +# Watch mode (great for dev workflow) |
| 142 | +npx jest --watch |
| 143 | + |
| 144 | +# Run tests in a specific file |
| 145 | +npx jest path/to/your/file.test.js |
| 146 | + |
| 147 | +# Run coverage report |
| 148 | +npx jest --coverage |
| 149 | + |
| 150 | +# Run with verbose output (get all the juicy details) |
| 151 | +npx jest --verbose |
| 152 | +``` |
| 153 | + |
| 154 | +Tests are located in the `/__tests__/` directory and use the real profanity files, so you know it’s legit 👀✅ |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## 🔀 Example Use Cases |
| 159 | + |
| 160 | +### ✅ Filter User Input |
| 161 | + |
| 162 | +```js |
| 163 | +async function filterInput(input) { |
| 164 | + if (await profanity.hasCurseWords(input)) { |
| 165 | + return '⚠️ Whoa there! Language, please.'; |
| 166 | + } |
| 167 | + return input; |
| 168 | +} |
| 169 | +``` |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +### 🌍 Multi-language Setup |
| 174 | + |
| 175 | +```js |
| 176 | +const en = new ProfanityEngine({ language: 'en' }); |
| 177 | +const es = new ProfanityEngine({ language: 'es' }); |
| 178 | + |
| 179 | +const englishResult = await en.search('bad'); |
| 180 | +const spanishResult = await es.search('malo'); |
| 181 | +``` |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +## 🌍 Want to Contribute? |
| 186 | + |
| 187 | +We love open source buddies 💛 |
| 188 | + |
| 189 | +### Add a New Language |
| 190 | + |
| 191 | +1. Fork it 🍴 |
| 192 | +2. Add a file to `/data/` named like `fr.txt` for French |
| 193 | +3. Fill it with one profane word per line |
| 194 | +4. Push & open a pull request! |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## 🙌 Who Made This? |
79 | 199 |
|
80 | | -Contributions to this module are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request on the GitHub repository. |
| 200 | +Built by [Robert James Gabriel](https://github.com/robertgabriel) and the good people at **Coffee & Fun LLC**. We make dev tools with accessibility, coffee, and good vibes in mind. |
81 | 201 |
|
82 | | -## License |
| 202 | +> Wanna support? Send a coffee our way or just spread the word! ☕🚀 |
83 | 203 |
|
84 | | -This project is licensed under the MIT License. |
| 204 | +--- |
85 | 205 |
|
86 | | -## Acknowledgments |
| 206 | +## 🧡 License |
87 | 207 |
|
88 | | -Special thanks to Robert James Gabriel and Coffee & Fun LLC for creating and maintaining this module, as well as the Jest team for the testing framework. Your efforts make this module more reliable and robust. |
| 208 | +[MIT](https://opensource.org/licenses/MIT) – because sharing is caring. |
89 | 209 |
|
90 | 210 | --- |
| 211 | + |
| 212 | +## 💬 Support & Community |
| 213 | + |
| 214 | +- 🐛 [Report Bugs](https://github.com/coffeeandfun/google-profanity-words/issues) |
| 215 | +- 💡 [Join Discussions](https://github.com/coffeeandfun/google-profanity-words/discussions) |
| 216 | +- 📬 Email: [support@coffeeandfun.com](mailto:hellow@coffeeandfun.com) |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +Made with ☕, code, and a sprinkle of magic at Coffee & Fun LLC 💖 |
| 221 | + |
| 222 | +## AI Usage |
| 223 | +Calude AI was used to help with this read me & adding extra Jest tests. |
0 commit comments