Yesterday I released a new module. I thought about it for a bit and decided to write about it.
The reason for this, is that I want to elaborate the reason for building this module, and at the same time perhaps supply a use-case to you.
I’m firmly against censoring anyone or anything, so I hope this module, if at all, gets used for the good.

Why I built it

We’re running and providing some very high-traffic communications services, one of them being chat.
The chat doesn’t allow you to share contact information (for security purposes) and so we needed a way to both sensor occurrences, and be notified whenever it happened.
When receiving notifications we also wanted to see the offending matches highlighted, and for that reason, I’ve added the highlight functionality.

The module was built with performance (regex, rather complex can become a slowing factor on high traffic messaging systems) and ease of use in mind.
It’s not rocket science, so it doesn’t need a freakishly large and complicated engine.

And thus, behold, the censoring module was born.

First, some code

Code speaks more than… Me. So here’s an example:

What it does

The module is compact, but does what it should do very well. What it does:

  • Supply a default set of filters
  • Supply the possibility to censor words
  • Supply the possibility to highlight matches (found abuses)
  • Detect words, even if they’ve b33n 13373d…
  • or s.p.l-i*t up.

What it doesn’t

To make sure you don’t get the wrong idea, I want to clear up some (already) misconceptions.

  • It doesn’t censor a predefined set of words.
  • It doesn’t actually censor by default.
  • It doesn’t swap words.

Where can I find the module?

Github: https://github.com/SpoonX/Censoring

NPM: https://www.npmjs.org/package/censoring

Installation is simple:

npm install --save censoring