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-js

v0.1.4

Published

A filter of swear words. 🤬

Downloads

386

Readme

Profanity

A filter of swear words.

Instalation

npm i profanity-js

API

This module exports a constructor function which takes an inputStr string and config object, to creates a Profanity instance.

Profanity(inputStr, config)

Creates a new Profanity instance.

Arguments

  • inputStr - Optional - A plain JavaScript string containing the value to be filtered.

  • config - Optional - A plain JavaScript object containing configuration options.

inputStr

  • Input string to evaluate if contains profanity.

config

Profanity configurations.

  • saveOriginal - Define if the original input string will be saved.
  • enabled - Define if the filter will be enabled.
  • placeHolder - Character used to replace profane words.
  • replaceRegex - Regular expression used to replace profane words with placeHolder.
  • separatorRegex - Regular expression used to split a string into words.
  • excludeWords - List of words to be ignored when filter profane words.
  • wordsList - List of words to be override the default dictionary of profane words.
  • language - Language used to filter profane texts.

Return value

A Profanity instance.

Resources

Every resource is accessed via your Profanity instance:

  • .censor() - Evaluate if string is profanity and return an edited version.
  • .isProfane() - Evaluate if a string is a profane language.
  • .censureWord() - Censure a word with placeHolder characters.
  • .loadOriginal() - Return original text if config.saveOrigial as true.
  • .addWords() - Add word(s) to wordlist filter.
  • .removeWords() - Remove word(s) from wordlist filter.

Usage

const Profanity = require('profanity-js');

1. Censor swear words from a text

By default, profanity replaces each swear words with the string length with asterisk *.

const profanity = new Profanity();

console.log(profanity.isProfane("merda"));
// log: true

let censoredText = profanity.censor("isso Ă© uma merda");
console.log(censoredText); 
// log: isso Ă© uma *****

2. Censor swear words with custom character (if in wordlits)

In .censor() asterisks in will be used to replace the swear words.

let censoredText = profanity.censor("You piece of sH1t");
console.log(censoredText); 
// log: You piece of ****

3. Check if the string contains any swear words

Function .isProfane() return True if any words in the given string has a word existing in the wordlist.

let dirtyText = "That l3sbi4n did a very good H4ndjob.";

console.log(profanity.isProfane(dirtyText));
// log: true

4. Add more censor words

let customBadwords = ['happy', 'sometext'];

profanity.addWords(...customBadwords);

console.log(profanity.isProfane("Happy day bro!"));
// log: true

5. Remove censor words

let removeBadwords = ['asshole'];

profanity.removeWords(...removeBadwords);

console.log(profanity.isProfane("Don't be an asshole"));
// log: false

6. Check if the string contains any swear words

Function .isProfane() return True if any words in the given string has a word existing in the wordlist.

let dirtyText = "That l3sbi4n did a very good H4ndjob.";

console.log(profanity.isProfane(dirtyText));
// log: true

7. Language support

The lib supports two languages they are Brazilian Portuguese and English, the defaults are Portuguese and to change this, see below.

let config = {
    language: "en-us"
};

let dirtyText = "fuck this shit";

const profanity = new Profanity(dirtyText, config)

console.log(profanity.censor());
// log: **** this ****

The config Object will be overwritten the default values.

8. Overrides placeHolder

To use a custom placeHolder, just overwritten the default value with a config Object.

let config = {
    placeHolder: "-"
};

let dirtyText = "fuck this shit";

const profanity = new Profanity(dirtyText, config)

console.log(profanity.censor());
// log: ---- this ----

9. Overrides default dictionary

To overrides the default profane dictionary, just set the new Array of words in config Object.

let config = {
    wordsList: ['shit', 'fuck', 'this']
};

let dirtyText = "fuck this shit";

const profanity = new Profanity(dirtyText, config)

console.log(profanity.censor());
// log: **** **** *****

Testing

npm run test

or

yarn test

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Contributing

If you want to contribute to a project and make it better, feel free to fork and contribute.

Special thanks to

  • youngkaneda - For help and support with the Regex expressions and make this code better.

Author

Made with ❤ by Rogério Araújo