npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

profanity-engine

v1.0.3

Published

Profanity Filter using Aho-Corasick algorithm

Readme

Profanity Filter

A powerful, efficient profanity detection and filtering library using the Aho-Corasick algorithm with Unicode normalization support.

Features

  • Fast Pattern Matching: Uses Aho-Corasick algorithm for efficient multi-pattern searching
  • Unicode Normalization: Detects profanity even when obfuscated with lookalike characters (e.g., h3ll0, ħëļļő)
  • Character Repetition Handling: Catches variations like heeeello or heeeeellllllo
  • Whitelist Support: Override blacklist matches with approved words
  • Word Boundary Detection: Optional strict matching at word boundaries only
  • Flexible Censoring: Replace detected profanity with custom mask characters

Installation

npm install profanity-engine

Quick Start

import { ProfanityFilter } from 'profanity-engine';

// Create a filter with blacklisted words
const filter = new ProfanityFilter(['badword', 'offensive']);

// Check if text contains profanity
filter.isProfane('This contains a badword'); // true

// Find all matches
const matches = filter.find('This has badword and offensive text');
// Returns: [
//   { word: 'badword', start: 9, end: 16 },
//   { word: 'offensive', start: 21, end: 30 }
// ]

// Censor profanity
filter.censor('This is a badword'); // "This is a *******"

Advanced Usage

With Whitelist

const filter = new ProfanityFilter(
  ['ass', 'hell'],
  ['lass', 'hello'] // Whitelist overrides
);

filter.isProfane('lass'); // false (whitelisted)
filter.isProfane('ass');  // true

With Options

const filter = new ProfanityFilter(
  ['bad'],
  [],
  {
    wordBoundary: true,    // Only match whole words
    logProfanity: true     // Log matches to console for debugging
  }
);

filter.isProfane('bad');      // true
filter.isProfane('badminton'); // false (wordBoundary: true)

Custom Censoring

const filter = new ProfanityFilter(['secret']);

filter.censor('This is secret', '#'); // "This is ######"
filter.censor('This is secret', '█'); // "This is ██████"

API Reference

Constructor

new ProfanityFilter(
  words: string[],
  whitelist?: string[],
  options?: ProfanityOptions
)

Parameters:

  • words: Array of blacklisted words to detect
  • whitelist: Optional array of words that override blacklist matches
  • options: Optional configuration object
    • wordBoundary: Only match words at word boundaries (default: false)
    • logProfanity: Enable console logging for debugging (default: false)

Methods

isProfane(text: string): boolean

Checks if the text contains any profane words.

filter.isProfane('clean text'); // false
filter.isProfane('bad text');   // true

find(text: string): Match[]

Returns all profanity matches found in the text.

const matches = filter.find('text with profanity');
// Returns: Array<{ word: string, start: number, end: number }>

censor(text: string, maskChar?: string): string

Censors profane words by replacing alphabetic characters with a mask character.

filter.censor('profane text');       // "******* text"
filter.censor('profane text', '#');  // "####### text"

How It Works

1. Unicode Normalization

The filter normalizes characters to prevent evasion through lookalike characters:

  • Homoglyphs: ħ → h, 3 → e, @ → a, $ → s
  • Accented letters: é → e, ñ → n, ü → u
  • Cyrillic/Greek: α → a, о → o, с → c
  • Fullwidth characters: A → a, 0 → 0

2. Repetition Squashing

Excessive character repetition is reduced to maximum 2 consecutive characters:

  • heeeeelloheello
  • baaaaaadbaad

3. Noise Character Removal

Punctuation and separators are ignored during matching:

  • b.a.dbad
  • h-e-l-lhell

4. Aho-Corasick Algorithm

Uses an efficient trie-based automaton for simultaneous multi-pattern matching in O(n + m) time, where n is text length and m is total matches.

Performance

  • Time Complexity: O(n + m) where n is text length, m is number of matches
  • Space Complexity: O(k) where k is total characters in all patterns
  • Efficiently handles thousands of blacklisted words
  • Single-pass text scanning

Limitations

  • Only supports text-based profanity detection
  • May have false positives with word boundary mode disabled
  • Requires comprehensive blacklist for effective filtering
  • Does not understand context or semantic meaning

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues, questions, or feature requests, please open an issue on GitHub.