Socket
Socket
Sign inDemoInstall

@cnakazawa/profane

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cnakazawa/profane

Zero dependency profanity detector.


Version published
Weekly downloads
1
Maintainers
1
Install size
18.9 kB
Created
Weekly downloads
 

Readme

Source

@cnakazawa/profane

Zero dependency profanity detector based on Swearjar and Profane.

Note: Some examples may contain offensive language for illustration purposes.

install

npm install @cnakazawa/profane

Usage

new Profane(options?)

Create a new instance:

import Profane from 'profane';

const profane = new Profane();

check(text: string): boolean

Check if a text matches the word list:

profance.check('Hell no'); // true
profance.check('H3ll no'); // true
profane.check('Banana Banana Banana'); // false

censor(censored: string, replacement?: string): string;

Censor words matching the word list:

profane.censor('Hell no'); // '**** no'
profane.censor('Hell no', '•'); // '•••• no'

getWordFrequencies(text: string): Record<string, number>;

Get the word frequencies of words matching the word list:


```js
const frequencies = profane.getWordFrequencies('horniest hornet fart');
{
  "horniest": 1,
  "fart": 1
}

getCategoryFrequencies(text: string): Record<string, number>;

Get the category frequencies of words matching the word list:

const frequencies = profane.getCategoryFrequencies('horniest hornet fart');
{
  "inappropriate": 1,
  "sexual": 1
}

Options

words: Record<string, ReadonlyArray<string>>

You can configure your Profane instance with a custom word list by supplying an object with word definitions:

const profane = new Profane({
  words: {
    happy: ['inappropriate'],
    awesome: ['elated'],
  },
});

profane.check('Mr. Happy is awesome'); // true
profane.getCategoryFrequencies('Mr. Happy is awesome'); // {inappropriate: 1, elated: 1}

You can receive a copy of the word list through the getWordList() function:

import {getWordList} from '@cnakazawa/profane';

getWordList(); // Record<string, ReadonlyArray<string>>

normalize?: boolean

Determines whether to normalize Leet or not. Defaults to true'.

new Profane({normalize: false}).check('H3ll'); // false
new Profane({normalize: true}).check('H3ll'); // true

wholeWordsOnly?: boolean

Whether to match only on whole words or not. Defaults to false'.

new Profane({wholeWordsOnly: false}).check('shell'); // true
new Profane({wholeWordsOnly: true}).check('shell'); // false

Updates to the word list

The default word list was lifted from Swearjar and may be out-of-date. Please feel free to send Pull Requests with new and updated definitions.

Keywords

FAQs

Last updated on 08 Feb 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc