Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

no-profanity

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

no-profanity

A JavaScript tool to detect and filter profanity

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.8K
increased by35.07%
Maintainers
1
Weekly downloads
 
Created
Source

no-profanity

A JavaScript tool to detect and filter profanity

Installation

npm i no-profanity

Usage

Using the no-profanity library is very simple. You can use it to detect profanity, or to filter profanity from a string. There are some basic options as well, such as overriding the placeholder character, or adding/removing words from the filterlist.

Check if a string contains profanity

A basic sample showing a simple checker

import { isProfane } from 'no-profanity';
console.log(isProfane("Don't be an asshole")); // true
console.log(isProfane("This is a nice text")); // false

Replace profanity in a string

A basic sample showing how to replace profanities

import { replaceProfanities } from 'no-profanity';
console.log(replaceProfanities("Don't be an asshole")); // Don't be an *******
console.log(replaceProfanities("This is a nice text")); // This is a nice text

Get profanities from a string

A basic sample returning the profanities

console.log(containsProfanities("what an asshole"));

Will return:

[ { 
    word: 'asshole', 
    index: 8 
} ]

Options

There are some overrides possible, but as soon as you want to use an override you will no longer be able pass a string to the functions defined above, but instead, they require an arguments object, like this:

replaceProfanities({
    testString: "testable string",
    options: {}
});

Override placeholder

The options object should contain a property called replacement which should be a string of length 1, unless you want a longer replacement value as the original wordlength. The default value is *.

replaceProfanities({
    testString: "testable string",
    options: {
        replacement: '#'
    }
});

Remove words from the filterlist

The options object should contain a property called excludes which should be an array of strings you don't want to filter on.

replaceProfanities({
    testString: "testable string",
    options: {
        excludes: ['testable']
    }
});

Add words to the filterlist

The options object should contain a property called includes which should be an array of strings you want to filter on.

replaceProfanities({
    testString: "testable string",
    options: {
        includes: ['testable']
    }
});

Contributing

Any contributions are highly appreciated. If you want to contribute, please fork the repository and create a pull request. If you have any questions, feel free to create an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details. With MIT comes the freedom to use the code for whatever you want, but a credit would be nice.

Keywords

FAQs

Package last updated on 24 Jul 2023

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