Contents
- Function: grawlix
- grawlix(str[, options])
- grawlix.isObscene(str[, filters, allowed])
- grawlix.getDefaults()
- grawlix.setDefaults(options)
- grawlix.hasPlugin(plugin)
- grawlix.loadPlugin(plugin[, pluginOptions])
- grawlix.Style
- grawlix.GrawlixPlugin
- grawlix.FilterTemplate
- grawlix.error
- grawlix.error.GrawlixFilterError
- grawlix.error.GrawlixPluginError
- grawlix.error.GrawlixStyleError
Replaces all obscenities in the given string with grawlixes.
var grawlix = require('grawlix');
var censored = grawlix(str); // uses default options
// or
var censored = grawlix(str, {
style: 'ascii',
randomize: true,
filters: [],
allowed: [],
plugins: [],
styles: []
});
Type: String
The content string to process. Required.
Type: Object
Optional. An object that may have any of the following properties:
style
: {String|Object} Required. The style of grawlix to use when replacing obscenities. Defaults to'ascii'
. To see the list of available default styles, see README#Grawlix Styles. To see all available style options -- including how to create new styles -- see the full Styles documentation.randomize
: {Boolean} Defines whether or not grawlixes should be built via random selection or taken directly from a map of fixed replacements (if supported by the style.) Defaults totrue
. Ignored when using a single-character style.filters
: {Array} An optional array of filter objects. For a full description of how to use this property, see the Filters documentation.allowed
: {Array} An optional array of strings, representing a whitelist of words that shouldn't be replaced.plugins
: {Array} An optional array ofgrawlix
plugins to include. See the Plugins documentation for more details.styles
: {Array} An optional array of grawlix style objects, used to add or configure styles aside from the main one specified by thestyle
option. See the full Styles documentation for more information on style objects.
A String
with all obscenities replaced by grawlixes.
Returns whether or not the given string contains known obscenities.
var isTextObscene = grawlix.isObscene(text); // uses default options
// or
var isTextObscene = grawlix.isObscene(text, filters); // with array of filter
// objects
// or
var isTextObscene = grawlix.isObscene(text, filters, allowed); // with array of
// filter options
// and whitelist
// or
var isTextObscene = grawlix.isObscene(text, null, allowed); // with just the
// whitelist
Type: String
The content string to check. Required.
Type: Array
Default: []
Optional. An array of filter objects. Identical to the filters
option described above.
Type: Array
Default: []
Optional. An array of strings, representing a whitelist of words that shouldn't be replaced. Identical to the allowed
option described above.
Boolean
-- true
if obscenity is found, false
otherwise.
Returns the current default options.
var defaultOptions = grawlix.getDefaults();
Object
which represents the current default options.
Sets the default options.
grawlix.setDefaults({
style: 'ascii',
randomize: true,
filters: [],
allowed: []
});
Type: Object
The default options to set. See (grawlix#Options)[#options] above.
Returns whether or not the given plugin has been added to the default options.
// find by name
var isInstalled = grawlix.hasPlugin('my-plugin-module');
// find by direct reference
var plugin = require('my-plugin-module');
var isInstalled = grawlix.hasPlugin(plugin);
Type: String
, GrawlixPlugin
, or Function
Name of plugin, GrawlixPlugin
object, or plugin factory function.
Boolean
-- true
if plugin found, false
otherwise.
Adds the given plugin to the default options.
// you can just provide the module name, like so...
grawlix.loadPlugin('plugin-module-name');
grawlix.loadPlugin('plugin-module-name', {
// plugin-specific config options can go here
});
// or you can load and provide the plugin yourself
var plugin = require('plugin-module-name');
grawlix.loadPlugin(plugin);
grawlix.loadPlugin(plugin, {
// plugin options
});
For convenience, this method can also be chained. Like so:
grawlix.loadPlugin('plugin-module-1')
.loadPlugin('plugin-module-2')
.loadPlugin('plugin-module-3');
Type: String
, GrawlixPlugin
, or Function
The plugin to add to the default options. Required.
Type: Object
Default: {}
Optional. A map of config options specifically for this plugin. See the plugin's own documentation to see what options are available (if any.)
The main grawlix
function, so as to enable chaining.
See Enumeration: grawlix.Style.
See Class: grawlix.GrawlixPlugin.
See Enumeration: grawlix.FilterTemplate.
To help in debugging issues related to the package, grawlix
throws three custom Error
subclasses that include extra information about the exception. These subclasses are exported under the grawlix.error
namespace for identification purposes (i.e. via instanceof
.)
Custom Error
subclass, thrown when an error occurs while loading a filter object. See Class: grawlix.error.GrawlixFilterError for details.
Custom Error
subclass, thrown when an error occurs while loading a plugin. See Class: grawlix.error.GrawlixPluginError for details.
Custom Error
subclass, thrown when an error occurs while loading a style object. See Class: grawlix.error.GrawlixStyleError for details.
Last updated April 18, 2017.