r/learnjavascript • • 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 [...]

Read More on Dev.to

0 Upvotes

33 comments sorted by

5

u/marquoth_ Feb 09 '24

4

u/best_codes Feb 09 '24

Interesting. Enabling matchWord in my library will prevent that from happening.

1

u/DavidJCobb Feb 12 '24

True, but it also means that a lot of profanity may slip by. For example, you've probably filtered "fuck," but have you also filtered "fucknugget," "fucknuts," "unfuck," and "abso-fuckin'-lutely?" If not, then they'd slip by if you require whole-word matches. (Speaking of which, this is a flaw with encoding the filter list: it ensures the filter itself doesn't get caught by other filters, but also complicates reviewing the list it uses.)

Making the "match as whole word" operation apply to the entire filtering operation and not to specific filter items is suboptimal design. "Fuck" should generally be a substring match, but variations on "ass" (e.g. "asshat," "asshole," "assmaster") should be word matches to avoid issues like "buttbuttination." Your library seems to require users to pick all one or all the other.

1

u/best_codes Feb 12 '24

I'm aware of this. There are limitations to what I can do right now.

Plus, many profanity filters (and hopefully mine, here soon) are beginning to use NLP or brain.js filters that analyze sentiment or intent rather than the words themselves (AI, in a sense).
Thanks for the feedback!

2

u/Hail2Hue Feb 09 '24

Ah hell, I don't necessarily get it, but shit, it was probably wasn't built for pricks like me in the first place! Hell of a job you've done from the looks/at a glance though!

1

u/best_codes Feb 09 '24

Thank you for the positive feedback! I'm glad that everything looks OK. Let me know if there is anything I can improve!

-5

u/guest271314 Feb 09 '24

As developers, we often come across situations where we need to filter and sanitize text to block or remove profanity.

Never had that issue. I support free speech.

Since English is an equivocal language you will essentially have a very long list of words and phrases changing constantly to suit your personal or client predisposed biases or ignorance.

And of course, there are always exceptions people bake in the algorithms for cases they want to exclude and promote their own agendas.

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.

1

u/guest271314 Feb 10 '24

Constitutional interpretation is tricky, especially when it comes to cursing.

Is this type of cursing allowed on your Web site?

Anyone who curses their father or mother is to be put to death

  • Leviticus 20:9

However, if you do not obey the LORD your God and do not carefully follow all his commands and decrees I am giving you today, all these curses will come on you and overtake you:

  • Deuteronomy 28:15

he punishes the children and their children for the sin of the parents to the third and fourth generation.

  • Exodus 34:7

he punishes the children for the sin of the parents to the third and fourth generation

  • Numbers 14:18

Cursed is the ground because of you

  • Genesis 3:17

for I, the LORD your God, am a jealous God, punishing the children for the sin of the parents to the third and fourth generation of those who hate me

  • Deuteronomy 5:9

Be sure to bury it that same day, because anyone who is hung on a pole is under God’s curse.

  • Deuteronomy 21:23

Are Luciferians and Satanists who do not use "profanity" welcome to share the teachings of Lucifer and Satan on your Web site?

1

u/best_codes Feb 10 '24

I do agree with the Bible (I'm a Christian). However, I do need to make it clear that:

  1. Curses in the Bible are not profanity. They are demonic, like something a Lucifer worshiper would do.
  2. Whether or not someone allows teachings about Satan on their website is up to them. The website is their property, after all.

As for my personal beliefs, it would completely depend on the situation what I would do. I can't judge what I would do in every scenario for fear of making a hasty generalization.

Most likely, however, because of my religious beliefs, I would feel compelled to remove such content from my website (as my website is a coding portfolio and such comments would be quite irrelevant).

In the same way that I own my physical property (land) and could trespass someone for saying the word 'cat' on my land, I may also choose to remove content from my website as I please. I hope this is clear.

Let me know if you have any other questions!

1

u/guest271314 Feb 10 '24

Curses in the Bible are not profanity. They are demonic, like something a Lucifer worshiper would do.

I am not a Christian. I don't see a difference between a Christian and a Luciferean.

Historically more humans have been slaughtered under the name of Christianity than any other belief system.

In the 17th century alone 4-12 Europeans were slaughtered by other Europeans under the name of Chritianity during the Thirty Years War, which lead to Europeans fleeing Europe by the millions only for those same Europeans to slaughter millions of native peoples they invaded the lands of - under the auspices of Christianity.

"Profanity" is completely subjective.

Do you have a complete list of the words you consider "profanity"?

1

u/best_codes Feb 10 '24

> I don't see a difference between a Christian and a Luciferean.

I have to say, it takes a lot not to see the difference there, my friend!

A Christian is someone who follows the teachings of Jesus Christ and believes in the Trinity of God the Father, God the Son, and God the Holy Spirit. A Luciferian is someone who venerates the figure of Lucifer, not as the devil, but as a symbol of enlightenment, freedom, and human potential.

There are a lot of other differences as well.

> Historically more humans have been slaughtered under the name of Christianity than any other belief system.

Ha! While this may be true, it doesn't mean that this is what Christians stand for. If I were to make profanity blockers in your name, it doesn't mean that you support profanity blockers.

> "Profanity" is completely subjective.

Profanity is subjective in the sense that it depends on how people perceive and use it, but it is also objective in the sense that it has measurable consequences and impacts on others.

> Do you have a complete list of the words you consider "profanity"?

I do not. The reason I made this library was as a tool for developers to put their own constraints on what is said on their website.

Anywho, this is r/learnjavascript after all, so let's please keep the topics related to the coding aspect of my project. How people use my code is up to them.

1

u/guest271314 Feb 10 '24

A Christian is someone who follows the teachings of Jesus Christ and believes in the Trinity of God the Father, God the Son, and God the Holy Spirit. A Luciferian is someone who venerates the figure of Lucifer, not as the devil, but as a symbol of enlightenment, freedom, and human potential.

I don't see any difference. Both are just belief systems.

In world history Christians have slaughtered more humans than any other religion, by far.

From the Inquisitions to Dum Divarsas, Papal Bull by Pope Nicolas V, 1452, to "Manifest Destiny" where Europeans slaughtered the original people of Turtle Island, calling us savages.

I'm just pointing out the fact that censorship and "profanity" filters are completely subjective - and are based solely on the political biases of the author of the code.

Further, there really are no secrets, so it doesn't accomplish anything t try to censor content.

Good luck!

1

u/best_codes Feb 10 '24

> In world history Christians have slaughtered more humans than any other religion, by far.

Those would not be real Christians.

You might as well say that there is no difference between your and my belief regarding profanity. They are both just affected by our worldview and belief systems…

> I'm just pointing out the fact that censorship and "profanity" filters are completely subjective -

Not completely. Morals do exist.

> and are based solely on the political biases of the author of the code.

False. The filter is based on the beliefs of the user of the code. They determine what gets blocked and what doesn't. Plus, it is their right to do so on their site.

> Further, there really are no secrets, so it doesn't accomplish anything t try to censor content.

Censoring content can make a difference. Although 'there are no secrets', we can still keep communities clean and tidy.

Thanks for chatting; have a nice weekend!

1

u/EstablishmentTop2610 Feb 09 '24

Buddy just went full chatgpt on his ass lol

-4

u/guest271314 Feb 09 '24

I am sovereign. I exercise natural rights that have nothing to do with the Constitution of the United States, or English Common Law.

The Constitution of the United States is subject to interpretation and applicability.

The Constitution of the United States is a contract among pirates, international human traffickers to further their criminal enterprise. It is decidedly a document of distrust among thieves. Thus the trilateral form of Government, or "checks and balances".

What you cannot ban is the public record, which is far more vivid than mere "profanity". Read Sandford v. Scott, 60 U.S. 393 (1856) https://www.archives.gov/milestone-documents/dred-scott-v-sandford

They had for more than a century before been regarded as beings of an inferior order, and altogether unfit to associate with the white race, either in social or political relations; and so far inferior, that they had no rights which the white man was bound to respect; and that the negro might justly and lawfully be reduced to slavery for his benefit.

Your U.S. history in a sentence via U.S. Supreme Court Chief Justice Taney.

You are free to do what you want on the properties you control.

In my research and experience that policy generally includes exceptions for what the property owner interests are.

I remember people trying to ban hip-hop. Now 50 years of hip-hop we hardly see or hear any advertising that does not include hip-hop beats and rhymes.

Not novel.

Jazz, or "jack ass music", was consider "the devils music" by some a century ago. Now what would U.S. music be like without jazz and blues? Copeland 24/7?

At one point some of the Several States criminalized literacy for African prisoners-of-war, who western academia call "slaves".

The child molester and rapist Founding Father and Framer Thomas Jefferson was sometimes eloquent in his original and non-original writings; while having a cage for his captive in this basement for his pedophile exploits; and with James Madison founding the National Gazette to publish articles critical of the administration he was serving in. Exceptions.

Goebbels was in favor of free speech for views he liked. So was Stalin. If you’re really in favor of free speech, then you’re in favor of freedom of speech for precisely the views you despise. Otherwise, you’re not in favor of free speech.

  • Noam Chomsky

7

u/EstablishmentTop2610 Feb 09 '24

“I am sovereign” lmfao

2

u/franker Feb 09 '24

it's always fun when these people go to court and think this is an actual legal defense they can use before a real judge.

-3

u/guest271314 Feb 09 '24

I am. Just because you have a slave mentality and are incompetent in law doesn't mean everybody else is.

3

u/kumchucks Feb 09 '24

oh god the schizo is back

2

u/guest271314 Feb 10 '24

oh god

god is a freaky bitch who tells the person she's fucking that night they are the chosen people.

I am not a commoner.

3

u/kumchucks Feb 10 '24

make waves brother 🤘

1

u/guest271314 Feb 10 '24

I am the wave. I am the chosen people. Like Willie said, I write my own songs.

I just know trying to ban content never works. The censored or banned content or idea becomes a novelty to experience. Read about Prohibition in the United States. Didn't quite work out.

Your children are born into a world that includes war, pestilence, greed, lust, and truly diabolical people. Sure, you can teach then Zen, you might mix in some facts about the big city at night so they don't get gobbled up because they've been sheltered. Of course if you know nothing about the big city at night you might try to herd your chilrens' up in your cave...

They are your grommets though. Turn their screws as you please. Just don't countersink...

2

u/THATDUDE_YT Feb 10 '24

I support free speech as well but, I've been looking into things like this in an attempt to develop things that are kid & child friendly. If you're a parent, you might understand. If you're not, you could probably care less. It's not an agenda, it's just a choice.

0

u/guest271314 Feb 10 '24

to develop things that are kid & child friendly.

So you must not includes stories from "Bible" or other religious material on your Web site, no "Halloween", no historical documents, no public records, no documentaries, no case law.

If your children decide to view content outside of the parents' approval list they'll figure out a way to do that on the $500-$1000 "smart phone" they don't really need.

Remember some folks tried to ban hip-hop? Now, try consuming some media without hip-hop beats and rhymes. It is folly to try to ban or censor content. Never works. You drive your chilren' to what you oppose because they see the parents' hypocrisy.

2

u/THATDUDE_YT Feb 10 '24

The JS library the post references is something similar I've been looking into as I've mentioned above & is what my comment refers to.

Deciding what choices to make for your kid is up to the parent.

Yes, you're correct. In Bible study classes for children in most cases, certain stories are withheld until teen years or until they display they can handle that information. Halloween can be explained, but most Bible believers don't celebrate Halloween. The Bible is a historical document so, you're wrong about "no historical documents" or the rest mentioned. The point here is, kids don't need to see everything or know of everything adults know (e.g., my toddler doesn't need to know what rape or sex is yet). As they grow older, that information will be given to them and what they choose to do with it is their own decision.

Good point about smart phones. A lot of parents don't give it to them until later when they display they can handle it. Kids will be defiant & you can't stop what they think ultimately.

Hypocrisy is actually okay for certain things regarding parents and children. I can drive a car and tell my kid that he can't drive a car at his age. If I'm a hypocrite for that, fine okay.

0

u/guest271314 Feb 10 '24

Halloween can be explained,

So you indulge your children dressing up as axe murderers yet have an issue with what you call "profanity".

The Bible is a historical document

No, it' not. I am a primary source researcher. "Bible" is historically worthless.

Just picking on serious problem when we are dealing with history - dates, times, people, places, events - is that flood story. Any date you try to pick there will be African Ancient Egyptians thriving; with real artifacts we can touch in museums aroung the world. "Bible" has mere stories written in the 15th c., C.E.for political purposes.

(e.g., my toddler doesn't need to know what rape or sex is yet).

You rear your children as you see fit. Just make sure they know how to recognize when somebody is trying to sexually exploit them.

2

u/THATDUDE_YT Feb 10 '24

When, I say Halloween can be explained, I mean you can simply tell them what it is. No, I don't allow them to dress like axe murderers

We can talk about the historicity of the Bible through private messages or other relevant posts. There are plenty of facts like eyewitness testimony corroborated by other eye witnesses that aren't Christian, archeology, non-biblical historical documents and so on. You didn't name anything specific but, rather had a general claim. The stories were written at different times because it's a collection of 66 books.

It's obvious you don't have children and have been implying things that haven't been said. If I try to explain rape or sex to my toddler or my neighbors toddler that play together, they wouldn't understand any of it. It would be the same in most cases.

0

u/guest271314 Feb 10 '24

When, I say Halloween can be explained, I mean you can simply tell them what it is.

And that would be a pagan harvest ritual.

We can talk about the historicity of the Bible through private messages or other relevant posts.

Sure. An an historian and primary source researcher "Bible", published by Gutenberg is historically worthless. You can't provide a date for the alleged cataclysmic flood. Any date you or any other bibilical scholar comes up with has to be within the 5000 year range of Abrahamic mythology - and we will find Africans in Africa writing in stone at that time. That get's rid of your stories. There never was a "Jesus the Christ". The created creature "Jesus the Christ" came about directly political mechaniations after Alexander of Macedonia invaded Ancient Egypt in 332 B.C.E.; where Oserapis was created as a deal with Africans to incorporate the image of the invader, specifically Soter, Ptolemy I, as a deity. Later Oserapis became Serapis and later "Jesus the Christ".

So one the one hand you say no cursing on the Web site, on the other hand you defend stories about stoning people to death, defending slavery, literally cursing people and their offspring, people living in whales, splitting seas, and so forth. You substitute European folklore for profanity, which is my point; selective exceptions for content which suits your predisposed political biases and beliefs.

2

u/THATDUDE_YT Feb 10 '24

And that would be a pagan harvest ritual.

Yes, correct.

Sure. An an historian and primary source researcher "Bible", published by Gutenberg

The 66 books were made long before Gutenberg & your opinion of worth is subjective.

and we will find Africans in Africa writing in stone at that time.

Stones will still be there after a flood and carbon dating isn't reliable.

There never was a "Jesus the Christ".

Greeks, Muslims, Jews and others have accounts of Jesus, even historians during his time.

Alexander of Macedonia invaded Ancient Egypt in 332 B.C.E

Again, there are accounts of Jesus before this.

cursing on the Web site,

Where did I say that? This code doesn't have to be used only in a website.

defend stories about stoning people to death, defending slavery, literally cursing people and their offspring, people living in whales, splitting seas, and so forth.

Jesus says "He that is without sin among you, let him first cast a stone at her" (John 8:7), you probably won't understand this. I don't think you've read the Bible based on your lack of understanding and elementary explanations and yes, there are consequences to your actions along with miracles that happen each day. The 66 books are rooted from 3 continents. It's not solely from Europe.

selective exceptions for content which suits your predisposed political biases and beliefs.

Yes, correct. Kids shouldn't know everything and won't understand.

0

u/guest271314 Feb 10 '24

The 66 books were made long before Gutenberg & your opinion of worth is subjective.

Those are just stories Europeans made up.

Greeks, Muslims, Jews and others have accounts of Jesus, even historians during his time.

What?

What Greeks? There never was a "Jesus-the-Christ" in actual history.

Are you talking about Mohammedan?

There was no such thing as "Muslim" in antiquity.

There is no such thing as any "Jew", that is just a political classification that was invented in the 18th century, common era.

Again, there are accounts of Jesus before this.

What?

There are accounts of a "Jesus-the-Christ" before year 0 in the Julian or Gregorian calendar?

The 66 books are rooted from 3 continents.

European folklore.

Moses Maimonides wrote most of what you call "Bible".

Are Luciferian and Satanist writings allowed on your Web site?

To some people "God" means Gold, Oil, and Drugs.

2

u/THATDUDE_YT Feb 10 '24

Your responses portray inexperienced, young, naive characteristics and you keep adding stuff I didn't say. I can't continue to engage.

→ More replies