New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@2toad/profanity

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@2toad/profanity

A JavaScript profanity filter

  • 2.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-76.87%
Maintainers
0
Weekly downloads
 
Created
Source

Profanity

GitHub Release Downloads Build status

A JavaScript profanity filter (with TypeScript support)

Getting Started

Install package

npm i @2toad/profanity

if you're using Node 11.x or older you'll need to install Profanity 1.x (e.g., npm i @2toad/profanity@1.4.0)

Usage

import { profanity } from '@2toad/profanity';
// or
var profanity = require('@2toad/profanity').profanity;


profanity.exists('I like big butts and I cannot lie');
// true

profanity.exists('I like big glutes and I cannot lie');
// false

profanity.censor('I like big butts (aka arses) and I cannot lie');
// I like big @#$%&! (aka @#$%&!) and I cannot lie

profanity.censor('I like big butts (aka arses) and I cannot lie', CensorType.FirstChar);
// I like big *utts (aka *rses) and I cannot lie

Options

Create an instance of the Profanity class to change the default options:

import { Profanity, ProfanityOptions } from '@2toad/profanity';

const options = new ProfanityOptions();
options.wholeWord = false;
options.grawlix = '*****';
options.grawlixChar = '$';

const profanity = new Profanity(options);

wholeWord

By default this is set to true, so profanity only matches on whole words:

profanity.exists('Arsenic is poisonous but not profane');
// false

Setting this to false, results in partial word matches:

profanity.exists('Arsenic is poisonous but not profane');
// true (matched on arse)

grawlix

By default this is set to @#$%&!:

profanity.censor('I like big butts and I cannot lie');
// I like big @#$%&! and I cannot lie

Setting this to ****, results in:

profanity.censor('I like big butts and I cannot lie');
// I like big **** and I cannot lie

grawlixChar

When specifying a CensorType other than CensorType.Word, this is the character used by the censor function.

By default this is set to *:

profanity.censor('I like big butts and I cannot lie', CensorType.AllVowels);
// I like big b*tts and I cannot lie

Setting this to $, results in:

profanity.censor('I like big butts and I cannot lie', CensorType.AllVowels);
// I like big b$tts and I cannot lie

Customize the word list

Add words:

profanity.addWords(['aardvark', 'zebra']);

Remove words:

profanity.removeWords(['butt', 'arse']);

Whitelist

The whitelist allows you to specify words that are always ignored by the profanity filter.

This can be useful if you want to turn partial word matching on (wholeWord = false), so combined words are caught (e.g., arselicker), while specific words you add to the whitelist are ignored (e.g., arsenic).

Add words to the whitelist:

profanity.whitelist.addWords(['arsenic', 'buttress']);

Remove words from the whitelist:

profanity.whitelist.removeWords(['arsenic', 'buttress']);

Contributing

So you want to contribute to the Profanikty project? Fantastic! Please read the Contribute doc to get started.

Keywords

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc