Make the Internet swear like a cartoon
grawlix is a configurable
RegExp-based profanity filter that swaps out obscene words for grawlixes -- long strings of emoticons or typographical symbols often used to represent swearing in comic strips and cartoons. Primarily aimed at George Carlin's "Seven Dirty Words", the library's default filters have been rigorously tested against potential false positives and Scunthorpe problems. It's highly extensible, allowing new words and grawlix styles to be easily added as needed.
Please note that, due to the subject matter, the
grawlix source code may be considered NSFW/Not Safe For Work, depending on an individual reader's circumstances. To see the full list of the words the library currently targets, see this file.
npm install grawlix --save
var grawlix = ;var censored = ; // outputs '%!@*'
Alternately, if you prefer not having to pass in options with every call, you can also configure the library's default settings with the
grawlix;// options will apply to every call made after this pointvar censored = ; // outputs '@$^!#@%@!#'
For even more options, see the full API documentation.
What style of grawlix the function should use when replacing curse words. To see the list of available styles, see the Grawlix Styles section below. To learn how to create your own styles, see the full Styles documentation.
Sets whether or not grawlixes should be built by randomly selecting from a list of characters, or taken directly from a map of fixed replacements. Ignored when using a single-character style.
Array of objects, representing either new words that should be replaced or configuration options for existing filters. For more information on how to use this property, see Adding New Filters below.
Array of strings, representing a whitelist of words that shouldn't be replaced. Passing in a word or list of words that's targeted by default will deactivate their associated filters.
For example -- the following code deactivates the filter
grawlix uses to replace the word 'bastard':
var censored =;
Array of plugins to include. See Using Plugins below for more details.
Seven different styles of grawlixes are available within the library by default. The three primary styles are:
'ascii': the default style. Generates grawlixes from the following standard typographical symbols:
'dingbats': Generates grawlixes from this list of Unicode-only symbols:
'unicode': Generates grawlixes from this combined list of standard typographical and Unicode-only symbols:
In addition, the following 'single-character' styles are also available:
'asterix': Replaces targeted words with asterixes, e.g.
'nextwave': Replaces targeted words with skull (
☠) symbols. Requires Unicode support.
'redacted': Replaces targeted words with
█symbols. Requires Unicode support.
'underscore': Replaces targeted words with underscores, e.g.
To use one of these styles, simply pass in the desired style's name in the
var censored =;// outputs '☠☠☠☠☠☠'
For information on advanced options, including on how to create new grawlix styles, see the full Styles documentation.
Adding New Filters
To ease the process of adapting to new demands (such as targeting obscene words not supported by default, or supporting languages other than English),
grawlix accepts new filters via the
options object. Let's say, for example, that you decide you want to prevent your forum users from discussing Unix's File System Consistency ChecK tool. You can add a filter targeting the word to the library's default settings like so:
For more information on creating and configuring filters, see the full Filters documentation.
Plugins are modules with additional functionality (such as new filters and styles) for
grawlix that can be easily shared among developers. Here's a running list of the plugins that are currently available:
- grawlix-racism: targets racial and ethnic slurs.
To use a plugin, install the module into your project and pass it in as part of your
var plugin = ;grawlix;// or alternatelygrawlix;
For more information on plugins (including how to create your own), see the full Plugin documentation.
Forks and pull requests welcome.
Depending on community response, the following areas and/or features could potentially be explored in the future:
- Default support for more curse words (depending on community needs)
- Browser support
- Internationalization / support for languages other than English
- Regular expression optimization
- Plugin framework
- Improve test coverage for util.js
- First draft of plugin framework. Feedback would be appreciated.
- Added digits to separator checks in filter regex patterns.