A simple node utility that removes/replaces profane words in given text. Very easily configurable wherein you can set the locale and replacement patterns of your choice.
The module uses the profane words curated and maintained by Shutterstock Project.
Default locale is en-base
Replacement Pattern | Default replacement Word/Characters | Sample Output |
---|---|---|
word | BLEEP | Your ass becomes Your BLEEP |
character | * | Your ass becomes Your *** |
grawlix | - | Your ass becomes You &!# |
Default replacement pattern is 'star'
Warning : Examples may contain offensive text
Replaces the bad words in the given inputString with the replacement pattern and replacement word passed to the function. For more usage examples please see javascript example.js
var cleanser = require('profanity-cleanser');
// Sets to default locale of en-base
cleanser.setLocale();
var inputString = "Your ass is shit"
// output becomes "You *** is ****"
var output = cleanser.replace(inputString);
var cleanser = require('profanity-cleanser');
// Sets to default locale of en-base
cleanser.setLocale();
var inputString = "Your ass is shit"
// output becomes "You FOOBAR is FOOBAR"
var output = cleanser.replace(inputString, 'word', 'FOOBAR');
var cleanser = require('profanity-cleanser');
// Sets to default locale of en-base
cleanser.setLocale();
var inputString = "Your ass is shit"
// output becomes "You !#$ is &^!@"
var output = cleanser.replace(inputString, 'grawlix');
Validates and sets the locale for profanity check based on the array passed. Acceptable locales map to the one's supported ./seeds directory. Setting locale implies using the badwords in the corresponding ./seeds/ file for profanity checking.
var cleanser = require('profanity-cleanser');
// Sets to default locale of en-base
cleanser.setLocale();
// Sets the locale to hindi spanish and japanese.
cleanser.setLocale(['hi', 'es', 'ja']);
Returns the currenly set locales.
var cleanser = require('profanity-cleanser');
//Set locale to hindi spanish and japanese
cleanser.setLocale(['hi', 'es', 'ja'])
var output = cleanser.getLocale();
// Outputs hi,es,ja
console.log(output.toString())
This method allows you to add more words of your choice to the dictionary.
var cleanser = require('profanity-cleanser');
cleanser.setLocale()
var output = cleanser.addWords(["foo", "bar"]);
var input = "Your ass foo is as shit as bar"
// Output : "Your *** *** is as **** as ***"
var output = cleanser.replace(input)
This method allows you to remove word from the dictionary.
var cleanser = require('profanity-cleanser');
cleanser.setLocale()
var output = cleanser.removeWords("ass");
var input = "Your ass is shit"
// Output : "Your ass is as ****"
var output = cleanser.replace(input)
This method returns a list of all the words currently in the profane words dictionary. Can be helpful in debugging.
var cleanser = require('profanity-cleanser');
cleanser.setLocale()
var output = cleanser.getDictionary();
-
This node module is based on the BanBuilder module written for php.
-
Also used @jwils0n's profanity-filter as reference for grawlix implementation.
-
Seed data for locale based bad words is obtained from Shutterstock Project.