Created
May 26, 2020 13:16
-
-
Save townofdon/55ad0291c830ef893b1333b2ca317b09 to your computer and use it in GitHub Desktop.
filter-bad-words.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const badwords = [ | |
'frick', | |
'fark', | |
'dern', | |
'shiz' | |
].join('|'); | |
const badEmojis = [ | |
'\\u{1F4A9}', // pile of poo | |
'\\u{1F595}' // middle finger | |
].join('|'); | |
const BADWORDS_REGEX = new RegExp(`(\\b(${badwords})\\b)|(${badEmojis})`, 'igu'); | |
function filterProfanity (text) { | |
return text.replace(BADWORDS_REGEX, '****'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment