### Installing bad-words library with Yarn Source: https://github.com/web-mech/badwords/blob/main/README.md Explains how to install the bad-words library using the Yarn package manager. Requires Yarn to be installed on your system. ```shell yarn add bad-words ``` -------------------------------- ### Initializing Filter with empty list in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Shows how to create a Filter instance that starts with no words in its blacklist. This is useful if you want to build the blacklist entirely dynamically. ```javascript const filter = new Filter({ emptyList: true }) filter.clean('hell this wont clean anything') //hell this wont clean anything ``` -------------------------------- ### Running bad-words tests with Yarn Source: https://github.com/web-mech/badwords/blob/main/README.md Provides the command to execute the automated test suite for the bad-words library using Yarn. Useful for verifying functionality after changes or installation. ```shell yarn test ``` -------------------------------- ### Using Filter to clean a string in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Demonstrates the basic usage of the Filter class to clean a string. Imports the Filter, creates an instance, and uses the clean method to replace bad words with the default placeholder. ```javascript import { Filter } from 'bad-words' ... const filter = new Filter(); console.log(filter.clean("Don't be an ash0le")); //Don't be an ****** ``` -------------------------------- ### Overriding Filter placeholder in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Shows how to customize the placeholder character used by the filter. Initializes the Filter with a configuration object specifying a custom character for replacing bad words. ```javascript const customFilter = new Filter({ placeHolder: 'x' }) customFilter.clean("Don't be an ash0le") //Don't be an xxxxxx ``` -------------------------------- ### Overriding Filter regex patterns in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Illustrates how to provide custom regex patterns for word matching and replacement. Useful for adapting the filter to different definitions of words or supporting multilingual character sets. ```javascript const filter = new Filter({ regex: /\*|\.|$/gi }) const filter = new Filter({ replaceRegex: /[A-Za-z0-9가-힣_]/g }) //multilingual support for word filtering ``` -------------------------------- ### Adding words to Filter blacklist in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Demonstrates multiple ways to add custom words to the filter's blacklist. Words can be added individually, from an array using the spread operator, or by providing a full list during initialization. ```javascript const filter = new Filter() filter.addWords('some', 'bad', 'word') filter.clean('some bad word!') //**** *** ****! //or use an array using the spread operator const newBadWords = ['some', 'bad', 'word'] filter.addWords(...newBadWords) filter.clean('some bad word!') //**** *** ****! //or const filter = new Filter({ list: ['some', 'bad', 'word'] }) filter.clean('some bad word!') //**** *** ****! ``` -------------------------------- ### Removing words from Filter blacklist in JavaScript Source: https://github.com/web-mech/badwords/blob/main/README.md Explains how to remove specific words from the filter's default blacklist. Words can be removed individually or from an array using the spread operator. ```javascript const filter = new Filter() filter.removeWords('hells', 'sadist') filter.clean('some hells word!') //some hells word! //or use an array using the spread operator const removeWords = ['hells', 'sadist'] filter.removeWords(...removeWords) filter.clean('some sadist hells word!') //some sadist hells word! ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.