Clean strings using Tagged Templates
mainYou can clean strings inline using tagged template literals. This is useful for cleaning both static literals and interpolated variables in one pass.
Using createFilter(options)
This is the recommended approach. It creates a specific tag bound to a configured filter instance.
Using the zero-config filter tag
For quick, default cleaning, use the exported filter tag. It is equivalent to calling createFilter() with no arguments.
import { createFilter, filter } from 'bad-words'
// Recommended: Create a configured tag
const filterTag = createFilter({ placeHolder: 'x', exclude: ['hells'] })
filterTag`Don't be an ash0le` //Don't be an xxxxxx
filterTag`you ${userInput}!` //interpolated values are cleaned too
// Quick use: Zero-config tag
filter`Don't be an ash0le` //Don't be an ******