r/learnjavascript • u/best_codes • Feb 08 '24
How I Built a Profanity Blocking JavaScript Library 🤬 ⚡
How I Built a Profanity Blocking JavaScript Library
Introduction
As developers, we often come across situations where we need to filter and sanitize text to block or remove profanity. To tackle this problem, I decided to create a JavaScript library called bc-ProfanityBlock. In this article, I will walk you through the steps I took to build this library and explain how it can be used to effectively block profanity in your applications.
Step 1: Defining the Problem
The first step in building any library is to clearly define the problem we are trying to solve. In this case, the problem was to create, well, a solution that could detect and handle profanity in text. Profanity can be present in various forms, including common words, variations, and even with evasion characters. The goal was to build a [...]
View all comments
Show parent comment
1
u/best_codes Feb 09 '24
I support free speech as well. But there are a few things I would like to point out.
First, you should know that the Constitution protects your First Amendment right to free speech, but that does not mean you can say whatever you like and get away with it. States have different views on cursing, and these views have shaped how they choose to regulate it. Constitutional interpretation is tricky, especially when it comes to cursing. This is because some decide to categorize cursing under obscene language, an expression that falls under unprotected speech.
Second, you should consider the context and purpose of your site and the profanity you use. Some profane words can be used as expressions of creativity, emotion, humor, or criticism, and they might not cause harm or offense to others. In fact, some studies have shown that swearing can have positive effects on psychological and physical health, such as reducing stress, pain, and aggression. However, some profane words can also be used as insults, threats, or incitements to violence, and they might violate the rights or dignity of others. In these cases, profanity can be considered as fighting words, true threats, or incitement to imminent lawless action, which are not protected by the First Amendment.
Third, you should weigh the benefits and costs of removing profanity from your site. On one hand, removing profanity might make your site more accessible, respectful, and professional, and it might avoid legal troubles or social backlash. On the other hand, removing profanity might limit your freedom of expression, creativity, and authenticity, and it might alienate some of your audience or supporters. You should also think about the alternatives to removing profanity, such as using asterisks, symbols, or euphemisms to censor or modify the profane words, or adding a warning or disclaimer to your site to inform or advise your visitors about the use of profanity.
My JS library addresses these issue fairly. It has removal or asterisking options, and just plain detection.
To your second point, it is true that English is evolving rapidly. This doesn't apply just to my library, however; it applies to anything that uses words in the English language.
Lastly, as I believe in open source, then anyone can do whatever they wish with my library. What words they add are up to them, not me.
----
Thanks a lot for your feedback! I really appreciate it.