2toad / profanity Goto Github PK
View Code? Open in Web Editor NEWA JavaScript profanity filter
License: MIT License
A JavaScript profanity filter
License: MIT License
Presently, if the words.txt file has any blank lines (including a blank line ending at the end of the file), the file import succeeds, but the blank lines are added to the words
array, which then wreaks havoc on the profanity filters.
The latest version won't install, it seems to be missing the entirety of the source code folder in the install
Hi there, thanks for this library.
I was just running it through an ID generator today to test it out, and printed out when it found an ID containing a bad word- these were some of the IDs it found (I'm using wholeWord=false ):
(I can't see any profanity here:)
MPEUGNMA
68Q56K5A
FCHZ6ZHA
UF7622DA
98AS3KVA
VFR9D5WA
4YX5AWVA
YVMNJU9A
DP4NMN8A
9PJMLM6A
ZNIVMM3A
XJMZC24A
These it found, which I can clearly see the profanity:
FFP7YFAG
S6FASSYJ
After writing this issue now, I can clearly see a pattern emerging. I think there is an issue happening with the input of the text from the file into the regex creation, which is causing one of the rules to include anything which ends with the letter A
.
This might be the culprit: a$$
- since $
represents "end of word" in regex.
In fact, I can confirm that, once I manually removed it from the words.txt file - I am not getting those false positives anymore.
Hi! ๐
Firstly, thanks for your work on this project! ๐. Love this little lib. Nice work!
We tested the module with Massterly
(African female name) and it showed:
M***terly
I think this might be fixed if we add the words before building the regex:
constructor(options?: ProfanityOptions) {
this.options = options || new ProfanityOptions();
this.whitelist = new List(() => this.buildRegex());
this.blacklist = new List(() => this.buildRegex());
this.blacklist.addWords(profaneWords);
}
would become:
constructor(options?: ProfanityOptions) {
this.options = options || new ProfanityOptions();
this.blacklist.addWords(profaneWords);
this.whitelist = new List(() => this.buildRegex());
this.blacklist = new List(() => this.buildRegex());
}
Today I used patch-package to patch @2toad/[email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@2toad/profanity/dist/profanity.js b/node_modules/@2toad/profanity/dist/profanity.js
index 9b64c31..0bc494a 100644
--- a/node_modules/@2toad/profanity/dist/profanity.js
+++ b/node_modules/@2toad/profanity/dist/profanity.js
@@ -8,9 +8,9 @@ const profane_words_1 = require("./data/profane-words");
class Profanity {
constructor(options) {
this.options = options || new profanity_options_1.ProfanityOptions();
+ this.blacklist.addWords(profane_words_1.default);
this.whitelist = new models_1.List(() => this.buildRegex());
this.blacklist = new models_1.List(() => this.buildRegex());
- this.blacklist.addWords(profane_words_1.default);
}
exists(text) {
this.regex.lastIndex = 0;
This issue body was partially generated by patch-package.
Add prettier and lint-staged
I was checking out this and was trying to implement it into my (NextJS) project.
I had quite a few words to add so I manually added them on the list on "profane-words.js" file, but the filter doesn't seem to work with the added words. Also noticed that profanity.addWords() and profanity.removeWords() only works on the instance where they are triggered, but I may be wrong.
I could use some help here.
Hi, I recently started using Profanity and think it is great.
I have an issue with the explicitly set Node engine in the package.json. Currently, it is set to "node": "14.15.0"
and it is causing issues in my environment which is running Node 15.
error @2toad/[email protected]: The engine "node" is incompatible with this module. Expected version "14.15.0". Got "15.2.0"
Currently, each time I run yarn add
I have to put a flag to --ignore-engines
to install properly.
Please can you set this to be Node 14 and above rather than the current version?
I'm using Yarn v1.22 with React v17.
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts'
Happily, this is working inside the application messages, but it returns many error messages in terminal like the one above.
I tried other versions from npm but none of them solved this issue.
This is the complete error:
Compiled with warnings.
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/index.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/index.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/censor-type.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/censor-type.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/index.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/index.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/list.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/list.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity-options.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity-options.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity.ts'
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/utils/misc.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/utils/misc.ts'
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
WARNING in ./node_modules/@2toad/profanity/dist/data/profane-words.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/data/profane-words.ts'
WARNING in ./node_modules/@2toad/profanity/dist/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/index.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/index.ts'
WARNING in ./node_modules/@2toad/profanity/dist/models/censor-type.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/censor-type.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/censor-type.ts'
WARNING in ./node_modules/@2toad/profanity/dist/models/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/index.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/index.ts'
WARNING in ./node_modules/@2toad/profanity/dist/models/list.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/list.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/models/list.ts'
WARNING in ./node_modules/@2toad/profanity/dist/profanity-options.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity-options.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity-options.ts'
WARNING in ./node_modules/@2toad/profanity/dist/profanity.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/profanity.ts'
WARNING in ./node_modules/@2toad/profanity/dist/utils/misc.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/utils/misc.ts' file: Error: ENOENT: no such file or directory, open '/home/joziasmartini/GitHub/bethype/Frontend/node_modules/@2toad/profanity/src/utils/misc.ts'
webpack compiled with 8 warnings
No issues found.
The code is already in good shape due to the current linting strategy. However, new linting strategies have been released since this project's inception, which will enforce even better best practices! New tools for building and deploying TypeScript have also emerged, and should be implemented improve the build/deployment process.
The attached file is a merge of the data found here and something claimed to be google's list. The next result is just over a thousand entries instead of fewer than 500. More is not better if too many false positive result, but I think this larger file is good. Changed from .ts to .txt just to upload it.
profane-words.txt
Husky is used for development of the Profanity lib. It is not used by the Profanity lib when Profanity is included as a dependency in a Node project. Unfortunately, there is no "dev only" script we can add to package.json that will run npm install
just within a dev environment.
Resolution: We need to remove the postinstall
script from package.json
tslint has been deprecated. Replace it with the latest version of eslint and eslint's Typescript plugin
When trying to compile you package with our web module the following error is output:
ERROR in ./node_modules/@2toad/profanity/dist/list.js Module not found: Error: Can't resolve 'fs' in 'C:\LocalProjects\DrawAlive_Web_Product\Server\Server\node_modules\@2toad\profanity\dist' @ ./node_modules/@2toad/profanity/dist/list.js 4:13-26 @ ./node_modules/@2toad/profanity/dist/profanity.js @ ./node_modules/@2toad/profanity/dist/index.js
Would prefer an alternative to the FS call.
so about 2 years ago i created a bot to work with this however i have been trying to modify it now so it uses different txt files for different servers now instead of one file.
i added a new option to ProfanityOptions
class ProfanityOptions { constructor() { this.wholeWord = true; this.grawlix = '****'; this.guildname = 'yolo'; } }
Which my bot can change WholeWord and Grawlix however its unable to change the guildname part that i added it in. no idea what im doing wrong. and the contact page and your website is refusing to work with me so i was just wondering if you could help explain what i need to-do to add more custom Options to the the profanity filter. i have the bot auto create txt files for every server it's connected to however this is the last part i need to try and sort out been sat here for about 6 hours trying to figure it out that im going mad.
Apologies for it not being an actual issue
Much appreciated, Dane
could we get a black list command?
for example we keep
options.wholeWord = false;
but for example
someone says 'cock' fair enough it censors it, but if someone says cockpit then it sensors it again
we want to keep the wholeWord to false as its a lot easier to mange than inserting every bit of word in to the file, is this possible?
Thanks, Dane
Please help!
Presently, the censor
method replaces the entire profane word with a grawlix. Thought it might be cool to add an option that only replaces the vowels in a profane word.
usePartialGrawlix
param to the censor
method. Default to false
.partialGrawlix
option to ProfanityOptions
. Defaults to '*'
.usePartialGrawlix
is true
, instead of the entire profane word being replaced with the grawlix
, only the vowels are replaced within the profane word. Each vowel is replaced with the partialGrawlix
value.import { Profanity, ProfanityOptions } from '@2toad/profanity';
const options = new ProfanityOptions();
options.partialGrawlix = '*';
const profanity = new Profanity(options);
profanity.censor('I like big butts (aka arses) and I cannot lie', true);
// I like big b*tts (aka *rs*s) and I cannot lie
How we can uncensored the word Password
keeping options.wholeWord = false
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.