UNPKG

node-profanity-filter

Version:

A Node.js profanity filter with support for exact matching, obfuscated word detection, and customizable replacement.

51 lines (50 loc) 1.61 kB
export interface FilterOptions { wordBoundaries?: boolean; parseObfuscated?: boolean; replaceWith?: string; disableDefaultList?: boolean; excludeWords?: string[]; includeWords?: string[]; } export declare class Filter { private words; private wordBoundaries; private parseObfuscated; private replaceWith; private static readonly WORD_REGEX; private static readonly charMap; constructor({ wordBoundaries, parseObfuscated, replaceWith, disableDefaultList, excludeWords, includeWords }?: FilterOptions); /** * Helper method to normalize obfuscated text * @param text * @param maxRepeats the max num of repeats allowed for a char * @returns */ private normalizeObfuscated; /** * Whether the string contains profane words * @param string * @param wordBoundaries match whole words (defaults to config) * @returns */ isProfane(text: string, wordBoundaries?: boolean): boolean; /** * Replace detected words * @param text * @param replaceWith word used for replacing ( defaults to config ) * @param wordBoundaries match whole words (defaults to config) * @returns */ sanitize(text: string, replaceWith?: string, wordBoundaries?: boolean): string; /** * Get a list of all matched words and their position * @param text * @param wordBoundaries match whole words (defaults to config) * @returns */ getMatches(text: string, wordBoundaries?: boolean): { word: string; start: number; end: number; }[]; }