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 🙏

© 2024 – Pkg Stats / Ryan Hefner

regexcensor

v1.1.0

Published

A JS regex-based profanity filter

Downloads

5

Readme

Filter

New Major Version is out - 1.1.0

CHANGES:

  • Rewritten to Rust (Performance boost)
  • .find() does not return every element uniquely anymore ['foo', 'foo', 'bar'] is no longer compressed to ['foo', 'bar']
  • Arrays of matches are now sets, hence not sorted chronologically
  • Built in support for arrays removed.

A regex based adaptable profanity filter.

npm i regexcensor

This module uses Rust's Fancy Regex, read more:

Importing the Filter

import Filter from 'regexcensor'

Predefined Filter Sets

If the input is a string, the filter will be set to a predefined swear preset.

const filter = Filter('PG13')

| Field | Description | | ------ | -------------------------------------------------------------- | | * | Include all possible negatively-associated words. | | PG13 | Less words filtered, minimum for a child-friendly environment. |

Configuring the Filter

If you want to configure a certain preset of of censored words, you can pass a configuring object like follows. All configurative attributes are optional.

const filter = Filter({
    fields: ['*'],
    mild: 3,
    patterns: [],
    words: [],
})

Fields

| Field | Description | | ------------ | ------------------------------------------------------------- | | * | Include all fields. | | sexual | General set of sexually-oriented swear words. | | sexuality | List of sexual orientations. | | racist | Set of racist swear words. | | historical | Historical or political ideas or terms, for example from WW2. | | religious | Religious terminilogy. |

Severity (Word mild)

Sets how severe the filter should be. 4 and 5 will censor almost all bad words and 0 and 1 only illegal ones.

Patterns

Define your own set of regex-defined patterns.

Words

RegexCensor provides an oversimplified regex construction.

For example, hello will automatically filter hellllllooooooo, he11o, but also h3110. End and/or start a word with * if the substring after or before doesn't matter. hello* will censor many hellos and hellowwwwwwssssss.

Methods

Filter.add(RegExp)

Adds the patterns to the filter, to quickly add regex arrays to the filter, use Filter.add_many(RegExp[])

Filter.add_word(string)

Adds a word to the filter, to quickly add arrays of words to the filter, use Filter.add_many_words(RegExp[])

Filter.check(string) : boolean

Checks one or several strings for profanity defined by the Filter. Returns true if any string triggers the patterns and false otherwise, to quickly check arrays with the filter, use Filter.check_many(string[]) : boolean

Filter.find(string) : string[]

Checks one or several strings for profanity defined by the Filter. Returns all emitted profane words.

Filter.find_patterns(string) : string[]

Checks one or several strings for profanity defined by the Filter. Returns all emitted regex pattern sources.

Filter.replace(string) : string

Replaces profanity in the string with asterisks.

Testing the Repository

  • Run npm run test to test the code with mocha.
  • Run npm run check to test different phrases in the console.
  • Run npm run codegen to generate rust code files from latin.txt and universal.txt
  • Run npm run build to build web assembly from rust code in /lib to /build
  • Run npm run wat to build web assembly textfile from wasm in /build

Sources

Inspired from: https://www.cs.cmu.edu/~biglou/resources/bad-words.txt Inspired from: https://github.com/Minehut/MinehutBOT/blob/master/src/util/censorRules.ts

No content was directly cloned or copied, I took my time to rethink every regex. The only thing that are similar are the words. This statement does not apply to latin.txt which is copied from https://github.com/dundalek/latinize/blob/master/latinize.js