UNPKG

profanity-checker-fr

Version:

French Profanity Filter is a lightweight and easy-to-use Node.js module to detect and filter offensive words (profanity, insults) in French sentences. Ideal for chat applications, comment moderation, and any service that requires clean user-generated cont

71 lines 2.61 kB
import { badWords } from './words/words.js'; // Import the list of predefined bad words /** * Configuration class for managing the profanity checker. * Contains settings like bad words, censored character, and whitelisted words. */ export class ProfanityConfig { static badWordsSet = new Set(badWords); static censoreSet = '*'; static whiteListWordsSet = new Set(); /** * This method allows you to change the default censor character. * You can use any string for replacement, e.g., '$' or '!'. * @param replacement - The string to use as the replacement for censored words. */ static changeCensoredWords(replacement) { this.censoreSet = replacement; } /** * Adds bad words to the badWordsSet. * Accepts either a single string or an array of strings. * @param words - The word(s) to add to the bad words set. */ static addBadWords(words) { if (typeof words === 'string') { this.badWordsSet.add(words.toLowerCase()); } else { words.forEach((word) => this.badWordsSet.add(word.toLowerCase())); } } /** * Deletes bad words from the badWordsSet. * Aceepts either a single string or an array of strings. * @param words - The word(s) to delete from the bad words set. */ static deleteBadWords(words) { if (typeof words === 'string') { this.badWordsSet.delete(words.toLowerCase()); } else if (Array.isArray(words)) { words.forEach((word) => this.badWordsSet.delete(word.toLowerCase())); } } /** * Adds words to the whitelist. Whitelisted words will not be censored. * Accepts either a single string or an array of strings. * @param words - The word(s) to add to the whitelist. */ static addWhiteList(words) { if (typeof words === 'string') { this.whiteListWordsSet.add(words.toLowerCase()); } else { words.forEach((word) => this.whiteListWordsSet.add(word.toLowerCase())); } } /** * Deletes words from the whitelist. * Accepts either a single string or an array of strings. * @param words - The word(s) to delete from the whitelist. */ static deleteWhiteList(words) { if (typeof words === 'string') { this.whiteListWordsSet.delete(words.toLowerCase()); } else if (Array.isArray(words)) { words.forEach((word) => this.whiteListWordsSet.delete(word.toLowerCase())); } } } //# sourceMappingURL=profanityConfig.js.map