LeoProfanity

LeoProfanity

new LeoProfanity()

Source:
LeoProfanity

Methods

(static) add(data)

Source:
Add word to the list
Example
// add word
filter.add('b00b');

// add word's array
// check duplication automatically
filter.add(['b00b', 'b@@b']);
Parameters:
Name Type Description
data string | Array.string

(static) badWordsUsed(str) → {Array.string}

Source:
Get list of used bad/profanity words
Example
// should return original string if string not contain profanity word
// output: []
filter.badWordsUsed('I have 2 eyes')

// should found profanity word
// output: ['zoophilia']
filter.badWordsUsed('lorem zoophilia ipsum')

// should detect case sensitive
// output: ['BoOb']
filter.badWordsUsed('I have BoOb')

// should detect multi occurrence
// output: ['boob', 'boob', 'ass']
filter.badWordsUsed('I have boob,boob, ass, and etc.')

// should not detect unspaced-word
// output: []
filter.badWordsUsed('Buy classic watches online')

// should detect multi-length-space and multi-space
// output: ['BoOb']
filter.badWordsUsed(',I h  a.   v e BoOb.')
Parameters:
Name Type Description
str string
Returns:
Type
Array.string

(static) check(str) → {boolean}

Source:
See:
Check the string contain profanity words or not Approach, to make it fast ASAP. Check out more cases on "clean" method
Example
// output: true
filter.check('I have boob');
Parameters:
Name Type Description
str string
Returns:
Type
boolean

(static) clean(str, replaceKeyopt, nbLettersopt) → {string}

Source:
Replace profanity words
Example
// no bad word
// output: I have 2 eyes
filter.clean('I have 2 eyes');

// normal case
// output: I have ****, etc.
filter.clean('I have boob, etc.');

// case sensitive
// output: I have ****
filter.clean('I have BoOb');

// separated by comma and dot
// output: I have ****.
filter.clean('I have BoOb.');

// multi occurrence
// output: I have ****,****, ***, and etc.
filter.clean('I have boob,boob, ass, and etc.');

// should not detect unspaced-word
// output: Buy classic watches online
filter.clean('Buy classic watches online');

// clean with custom replacement-character
// output: I have ++++
filter.clean('I have boob', '+');

// support "clear letter" in the beginning of the word
// output: I have bo++
filter.clean('I have boob', '+', 2);
Parameters:
Name Type Attributes Default Description
str string
replaceKey string <optional>
* one character only
nbLetters string <optional>
0 number of ignoring letters from the beginning
Returns:
Type
string

(static) clearList()

Source:
Clear all words in the list

(static) getDictionary(nameopt) → {Array.string}

Source:
Return word list from dictionary
Example
// returns words in en dictionary
filter.getDictionary();

// returns words in fr dictionary
filter.getDictionary('fr');
Parameters:
Name Type Attributes Default Description
name string <optional>
en dictionary name
Returns:
Type
Array.string

(static) list() → {Array.string}

Source:
Return all current profanity words
Example
filter.list();
Returns:
Type
Array.string

(static) loadDictionary(nameopt)

Source:
Load word list from dictionary to using in the filter
Example
// replace current dictionary with the french one
filter.loadDictionary('fr');

// replace dictionary with the default one (same as filter.reset())
filter.loadDictionary();
Parameters:
Name Type Attributes Default Description
name string <optional>
en

(static) remove(data)

Source:
Remove word from the list
Example
// remove word
filter.remove('b00b');

// remove word's array
filter.remove(['b00b', 'b@@b']);
Parameters:
Name Type Description
data string | Array.string

(static) reset()

Source:
Reset word list by using en dictionary (also remove word that manually add)