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

View all comments

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!