react-badword
v2.1.3
Published
A React hook for filter badwords
Downloads
21
Maintainers
Readme
react-badword
A React hook for filter badwords
Installation
npm i react-badword --save
Usage
import { useBadWords } from 'react-badword';
const {
filterBadWord,
} = useBadWords();
console.log(filterBadWord("What the hell")); // What the ****
Placeholder Overrides
const options = {
placeholder: '#'
};
const {
filterBadWord,
} = useBadWords(options);
console.log(filterBadWord("What the hell")); // What the ####
Add words to the blacklist
const blackList = ['ass', 'cum'];
const {
addWords,
} = useBadWords();
useEffect(() => {
addWords(blackList);
}, []);
console.log(filterBadWord("cum to me")); // *** to me
Instantiate with an empty list bad words
const options = {
emptyList: true
};
const {
filterBadWord,
} = useBadWords(options);
console.log(filterBadWord("What the hell")); // What the hell
Remove words from the blacklist
const whiteList = ['ass', 'cum'];
const {
removeWord,
} = useBadWords();
useEffect(() => {
removeWord(whiteList);
}, []);
console.log(filterBadWord("cum to me")); // cum to me
Check for obscene content
const {
hasBadWord,
} = useBadWords();
console.log(hasBadWord("cum to me")); // true
Parameters