profanity-cleanser
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.
Locales supported
The module uses the profane words curated and maintained by Shutterstock Project.
Default locale is en-base
Supported replacement patterns
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'
methods
Warning : Examples may contain offensive text
cleanser.replace(inputString, replacementPattern, replacementWord)
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
Default replacement
var cleanser = ; // Sets to default locale of en-basecleanser; var inputString = "Your ass is shit" // output becomes "You *** is ****"var output = cleanser;
Replacement with word of your choice
var cleanser = ; // Sets to default locale of en-basecleanser; var inputString = "Your ass is shit" // output becomes "You FOOBAR is FOOBAR"var output = cleanser;
Replacement with grawlix (i.e. random special characters)
var cleanser = ; // Sets to default locale of en-basecleanser; var inputString = "Your ass is shit" // output becomes "You !#$ is &^!@"var output = cleanser;
cleanser.setLocale([string])
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 = ; // Sets to default locale of en-basecleanser; // Sets the locale to hindi spanish and japanese.cleanser;
cleanser.getLocale()
Returns the currenly set locales.
var cleanser = ; //Set locale to hindi spanish and japanesecleanser var output = cleanser; // Outputs hi,es,jaconsole
cleanser.addWords([string])
This method allows you to add more words of your choice to the dictionary.
var cleanser = ; cleanser var output = cleanser; var input = "Your ass foo is as shit as bar" // Output : "Your *** *** is as **** as ***"var output = cleanser
cleanser.removeWords(string)
This method allows you to remove word from the dictionary.
var cleanser = ; cleanser var output = cleanser; var input = "Your ass is shit" // Output : "Your ass is as ****"var output = cleanser
cleanser.getDictionary()
This method returns a list of all the words currently in the profane words dictionary. Can be helpful in debugging.
var cleanser = ; cleanser var output = cleanser;
References
-
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.