bad-words-checker
is an npm package designed to detect and censor harmful words in text content. This package is especially useful for protecting children from exposure to violent, sexually explicit, and discriminatory language. It supports multiple languages including English, Arabic, Chinese, French, German, Greek, Hebrew, Hindi, Indonesian, Italian, Japanese, Korean, Portuguese, Russian, Spanish, Thai, and Vietnamese.
The package supports the following languages: English Arabic Chinese French German Greek Hebrew Hindi Indonesian Italian Japanese Korean Portuguese Russian Spanish Thai Vietnamese
To install bad-words-checker
, run the following command:
npm install bad-words-checker
Usage
Below is an example of how to use bad-words-checker in your project:
import {
RegExpMatcher,
TextCensor,
englishDataset,
englishRecommendedTransformers,
} from 'obscenity';
import {
checkChineseText,
checkFrenchText,
checkGermanText,
checkGreekText,
checkHebrewText,
checkHindiText,
checkItalianText,
checkJapaneseText,
checkKoreanText,
checkPortugueseText,
checkRussianText,
checkSpanishText,
checkThaiText,
checkVietnameseText,
} from 'bad-words-checker';
// Initialize the English matcher
const englishMatcher = new RegExpMatcher({
...englishDataset.build(),
...englishRecommendedTransformers,
});
// Function to check text based on selected language
const checkText = (language, text) => {
let result;
switch (language) {
case 'hindi':
result = checkHindiText(text);
break;
case 'chinese':
result = checkChineseText(text);
break;
// Add cases for other languages as needed
// ...
default:
result = englishMatcher.replace(text, '*');
}
return result;
};
// Example usage
const textToCheck = "your text here";
const language = "hindi"; // Change to desired language
const result = checkText(language, textToCheck);
console.log(result);