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

profanity-util

v0.2.0

Published

Utility for detection, filtering and replacement / obscuration of forbidden words

Downloads

1,801

Readme

Node.js Profanity Utility

Build Status

Utility for detection, filtering and replacement / obscuration of forbidden words

The original list of swearwords used by default was taken from here.

Please note: This small utility module is written to prevent or monitor the use of certain words in your content without keeping context in account. An improper use may compromise the meaning of your content. Keep in account when using.

Install

npm install profanity-util

API

profanity.check(targetString, [ options ])

Returns a list of forbidden words found in a string.

Arguments

  • targetString - String to search
  • options (Optional) - Listed below

Options

  • forbiddenList - Array containing forbidden terms
  • substrings: [ true | "lite" ] - If set will match substrings as well (default false).
  • subStringList: If the substrings property is set to "lite" a second, less strict word list can be passed in for use in the substring profanity filter.

The "lite" option is intended to reduce false positives in substring matching, where you may wish to use substring matching but allow terms such as "liverpool" or "classic". PLEASE NOTE This may become the default setting for substring matching in future versions.

Example

var profanity = require('profanity-util');

console.log(profanity.check('Lorem ipsum foo bar poop test poop damn dolor sit..'));
// [ 'poop', 'poop', 'damn' ]

// With substring matching
var profanity = require( 'profanity-util', { substring: true } );

console.log(profanity.check('Lorem ipsum liverpool foo bar poop test classic damn dolor sit..'));
// [ 'poo' 'poop', 'ass', 'damn' ]

// With substring matching set to "lite"
var profanity = require( 'profanity-util', { substring: "lite" } );

console.log(profanity.check('Lorem ipsum liverpool foo bar poop test classic damn dolor sit..'));
// [ 'poop', 'damn' ]

Note the default word list for "lite" substring matching still returns a match for the "Seven Dirty Words" and their cousins.

profanity.purify(target, [ options ])

Purifies a string or strings contained in a given object or array from forbidden words.

If an object is given as target, this method will recursively loop through its values and purify every string.

By default forbidden swearwords will be obscured in this format: a***b, although setting replace option to true will activate replacement mode, which replaces each forbidden word with a random entry from a small list of inoffensive words (See DEFAULT_REPLACEMENTS in lib/profanity.js). This mode could be a fun and different approach to discourage and prevent swearing on your platform / app.

The .purify method will return an Array containing two values:

  1. The purified String / Object / Array
  2. An Array containing all swearwords obscured / replaced

Arguments

  • target - Object, Array or String to purify
  • options (Optional) - Purification options (Explained below)

Options

  • forbiddenList - Array of forbidden terms to replace or obscure
  • replacementsList - Array of replacement words (To pick randomly from)
  • obscureSymbol - Symbol used to obscure words if obscured is set to true
  • replace - If set to true it will replace forbidden words (e.g., poop -> rainbows) instead of obscuring them
  • map - If true, reoccurring forbidden words will always be replaced by the same substitute (e.g., all poop -> unicorn and all damn -> rainbows). This only works in conjunction with replace.
  • substrings - If true, match substrings as well (false by default).

Examples

Obscure mode (default)

var profanity = require('profanity-util');

console.log(profanity.purify('lorem ipsum foo damn bar poop'));
// [ 'lorem ipsum foo d**n bar p**p, [ 'damn', 'poop' ] ]

console.log(profanity.purify({
	foo: 'poop',
	bar: { nested: 'damn', arr: [ 'foo', 'poop' ] }
}));
// [ { foo: 'p**p', bar: { nested: 'd**n', arr: [ 'foo', 'p**p' ] } }, [ 'poop', 'damn', 'poop' ] ]

Obscure mode, custom options

var profanity = require('profanity-util');

console.log(profanity.purify('foo poop', { obscureSymbol: '$' }));
// [ 'foo p$$p', ['poop'] ]

console.log(profanity.purify('foo poop', { forbiddenList: [ 'foo', 'bar' ] }));
// [ 'f*o poop', ['foo'] ]

Replace mode ({ replace: true })

var profanity = require('profanity-util');

console.log(profanity-util.purify('lorem ipsum foo damn bar poop'));
// [ 'lorem ipsum foo gingerly bar rainbows', [ 'damn', 'poop' ] ]

console.log(profanity-util.purify({
	foo: 'poop',
	bar: { nested: 'damn', arr: [ 'foo', 'poop' ] }
}));
// [ { foo: 'kitten', bar: { nested: 'unicorn', arr: [ 'foo', 'puppy' ] } }, [ 'poop', 'damn', 'poop' ] ]

Contribute

All contributions are welcome as long as tests are written.

License

Copyright (c) 2014, 2017 Kano Computing Ltd. - Released under The MIT License.