UNPKG

deep-profanity-filter

Version:

A thorough profanity filter that considers most common circumventions. Works with your custom list of blocked and whitelisted words and phrases. Identifies and/or replaces bad words. Works with *wildcards* at *start and/or end* of words.

202 lines â€ĸ 13.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduceRepeatCharacters = exports.textToLatin = exports.removeTextAccents = exports.unEmoji = void 0; /** * Replaces all emojis in a text that feature a letter with * normal latin characters. * Example: "đŸ‡Ŧ⭕ 🔛" turns into "go on" or * "đŸ…ŋđŸ‡ēÂŽī¸đŸ’°đŸ‡Ē" turns into "purse". * Note: This does NOT replace random emojis used to represent * or mask letters, such as '🌸' representing an 'O'. * * Suggested usage: `textToLatin(unEmoji(inputText))` * @param {string} inputText - The text from which you would like to remove all text based emojis. * @returns the input text, with all letter based emojis transformed to become text. */ function unEmoji(inputText) { return inputText .replace(/🆔/g, 'id') .replace(/🆚/g, 'vs') .replace(/🔤/g, 'abc') .replace(/🆎/g, 'ab') .replace(/🆑/g, 'cl') .replace(/🆘/g, 'sos') .replace(/🚾/g, 'wc') .replace(/🆖/g, 'ng') .replace(/🆗/g, 'ok') .replace(/🆙/g, 'up') .replace(/🆒/g, 'cool') .replace(/🆕/g, 'new') .replace(/🔟/g, '10') .replace(/🆓/g, 'free') .replace(/🔚/g, 'end') .replace(/🔙/g, 'back') .replace(/🔛/g, 'on') .replace(/🔝/g, 'top') .replace(/🔜/g, 'soon') .replace(/đŸ‡Ļ|🅰/g, 'a') .replace(/🇧|🅱/g, 'b') .replace(/🇨|ÂŠī¸/g, 'c') .replace(/🇩/g, 'd') .replace(/đŸ‡Ē/g, 'e') .replace(/đŸ‡Ģ/g, 'f') .replace(/đŸ‡Ŧ/g, 'g') .replace(/🇭/g, 'h') .replace(/🇮/g, 'i') .replace(/đŸ‡¯/g, 'j') .replace(/🇰/g, 'k') .replace(/🇱/g, 'l') .replace(/🇲/g, 'm') .replace(/đŸ‡ŗ/g, 'n') .replace(/🇴|🅾|⭕/g, 'o') .replace(/đŸ‡ĩ|đŸ…ŋ/g, 'p') .replace(/đŸ‡ļ/g, 'q') .replace(/🇷|ÂŽī¸/g, 'r') .replace(/🇸|💰/g, 's') .replace(/🇹/g, 't') .replace(/đŸ‡ē/g, 'u') .replace(/đŸ‡ģ/g, 'v') .replace(/đŸ‡ŧ/g, 'w') .replace(/đŸ‡Ŋ|❎|❌/g, 'x') .replace(/🇾/g, 'y') .replace(/đŸ‡ŋ/g, 'z'); } exports.unEmoji = unEmoji; /** * Removes most common accents from characters. * Example: The text "ZĖĩÍĖ­ĖĄaĖļĖ‰Í„ĖŦ˘lĖļÍ—ĖœgĖĩÍ’ÍĖœĖ˛oĖļĖ…ĖŠĖž" becomes "Zalgo", * the text "à-côtÊs" becomes "a-cotes", * non-latin characters stay non-latin, e.g. "ᑕⓞ֑ÎŋĖ¤Í•đ•ƒ×…Ü‘" becomes "ᑕⓞÎŋ𝕃". * @param {string} inputText - The text for which you wish to have all * accents removed. * @returns the input text, stripped of all accents. */ function removeTextAccents(inputText) { return inputText .normalize('NFD') .replace(/[\u0300-\u036f]|[\u0591-\u05bd]|\u05bf|\u05c1|\u05c2|\u05c4|\u05c5|\u05c7|\u0711|[\u0730-\u074a]/g, ''); } exports.removeTextAccents = removeTextAccents; /** * Converts a text of fancy unicode font to latin alphabet characters. * This translation happens based on "visual appearance" of the letters, * so if you do this to text that is written in a language of non-latin * alphabet, you will get weird outputs. * * Disclaimer: This may at times mistranslate messages, and the list of * characters that get converted is most likely not complete, although * it is very thoroughly assembled. It will remove most common accents, * and returns a latin string in lower case letters. Any characters that * could not be mapped to latin characters will still appear in the string. * * Example: * "áĩēâ“˜ę¯ą ₎Ꮛ䚂Շ" would turn into "this text" or "ZĖĩÍĖ­ĖĄaĖļĖ‰Í„ĖŦ˘lĖļÍ—ĖœgĖĩÍ’ÍĖœĖ˛oĖļĖ…ĖŠĖž" turns into "zalgo", or * "ᑕⓞ֑ÎŋĖ¤Í•đ•ƒ×…Ü‘" turns into "cool". * * Suggested usage: `textToLatin(unEmoji(inputText))` * @param {string} inputText - The text which you would like to convert to latin * @returns the input text, with foreign or special alphabet letters translated * to latin lower case characters */ function textToLatin(inputText) { inputText = removeTextAccents(inputText); inputText = unEmoji(inputText); // replace upper case letters that look different in lower case inputText = inputText .replace(/Ð/g, 'd') .replace(/ÎŖ/g, 'e') .replace(/á‚ē/g, 'g') .replace(/Η/g, 'h') .replace(/Ꮰ/g, 'j') .replace(/Μ/g, 'm') .replace(/Ꭴ/g, 'q') .replace(/Շ/g, 't') .replace(/Ôą/g, 'u') .replace(/Հ/g, 'z'); // convert to lower case and replace the rest inputText = inputText.toLowerCase(); return inputText .replace(/ᴀ|ₐ|á´Ŧ|áĩƒ|Îą|âąĨ|ɐ|áļ|áēš|𝐚|𝐀|ⓐ|𝔞|𝔄|𝖆|đ•Ŧ|đ“Ē|𝓐|đ’ļ|𝒜|𝕒|𝔸|īŊ|🄰|ɑ|⏄|𝗮|𝗔|đ˜ĸ|𝘈|𝙖|đ˜ŧ|𝚊|𝙰|Îģ|â‚ŗ|卂|īž‘|ᗩ/g, 'a') .replace(/ᴁ|ÃĻ|ᴂ/g, 'ae') .replace(/ęœĩ/g, 'ao') .replace(/朎/g, 'au') .replace(/ꜹ/g, 'av') .replace(/ęœģ|机/g, 'aa') .replace(/ęœŊ/g, 'ay') .replace(/ʙ|ᴃ|в|áĩĻ|á´Ž|áĩ‡|ɓ|ƀ|ƃ|áĩŦ|áļ€|𝐛|𝐁|ⓑ|𝔟|𝔅|𝖇|𝕭|đ“Ģ|𝓑|𝒷|đĩ|𝕓|𝔹|īŊ‚|🄱|â„Ŧ|ΐ|āš’|ⴆ|ÉŽ|ᏸ|áƒĒ|āš–|đ—¯|𝗕|đ˜Ŗ|𝘉|𝙗|đ˜Ŋ|𝚋|𝙱|ß|ā¸ŋ|䚃|Ō|β|ᗷ/g, 'b') .replace(/ᴄ|áļœ|Âĸ|ƈ|Čŧ|ꞇ|𝒸|ɕ|áļ—|ɔ|ↄ|ᴐ|𝐜|𝐂|ⓒ|𝔠|ℭ|𝖈|𝕮|đ“Ŧ|𝓒|𝒞|𝕔|ℂ|īŊƒ|🄲|áĨ´|🅲|Ī‚|ፈ|𝗰|𝗖|𝘤|𝘊|𝙘|𝘾|𝚌|𝙲|ᄃ|â‚ĩ|匚|â†ģ|ᑕ|á‘ĸ|℃/g, 'c') .replace(/ᴅ|á´°|áĩˆ|∂|ęē|ɗ|đ|ƌ|𝒹|ČĄ|áļ‘|áĩ­|áļ|ɖ|𝐝|𝐃|ⓓ|𝔡|𝔇|𝖉|đ•¯|𝓭|𝓓|𝒟|𝕕|đ”ģ|īŊ„|đŸ„ŗ|á—Ē|áĻ”|ÕĒ|đŸ…ŗ|āš”|ԃ|ꮄ|āģ“|𝗱|𝗗|đ˜Ĩ|𝘋|𝙙|đ˜ŋ|𝚍|đ™ŗ|り|ę­°|ᕲ/g, 'd') .replace(/Įŗ|Į†/g, 'dz') .replace(/ᴇ|ₑ|á´ą|áĩ‰|âąģ|ɛ|Ņ”|ɇ|Éĩ|ęœŋ|Į|⹸|áļ’|áļ“|ɘ|𝐞|𝐄|ⓔ|đ”ĸ|𝔈|𝖊|𝕰|𝓮|𝓔|𝑒|𝐸|𝕖|đ”ŧ|īŊ…|🄴|🅴|ŌŊ|ꮛ|𝗲|𝗘|đ˜Ļ|𝘌|𝙚|𝙀|𝚎|𝙴|乇|Ξ|á˜ŋ|â‚Ŧ|𝒆|ᗴ/g, 'e') .replace(/朰|áļ |ƒ|ʄ|ꝭ|đ’ģ|ęŧ|áĩŽ|áļ‚|áēœ|áē|Ō“|áĩŗ|𝐟|𝐅|ęŸģ|ⓕ|đ”Ŗ|𝔉|𝖋|𝕱|đ“¯|𝓕|𝐹|𝕗|đ”Ŋ|īŊ†|đŸ„ĩ|ℱ|𝒇|á ģ|⨍|đŸ…ĩ|Ī|đ—ŗ|𝗙|𝘧|𝘍|𝙛|𝙁|𝚏|đ™ĩ|ÂŖ|â‚Ŗ|ę­ļ|千|īŊˇ|ᖴ/g, 'f') .replace(/īŦ/g, 'fi') .replace(/īŦ‚/g, 'fl') .replace(/īŦ€/g, 'ff') .replace(/īŦƒ/g, 'ffi') .replace(/īŦ„/g, 'ffl') .replace(/Éĸ|ʛ|á´ŗ|áĩ|É |ĮĨ|áļƒ|ÉĄ|áĩˇ|𝓰|𝐠|𝐆|ⓖ|𝔤|𝔊|𝖌|𝕲|𝓖|𝑔|đ’ĸ|𝕘|𝔾|īŊ‡|đŸ„ļ|Ų‚|ᧁ|đŸ…ļ|īģŽ|ꮆ|āē‡|𝗴|𝗚|𝘨|𝘎|𝙜|𝙂|𝚐|đ™ļ|₲|ム|ց|ᘜ/g, 'g') .replace(/Ɯ|ĐŊ|ₕ|á´´|ʰ|⹨|ħ|ÉĻ|ÉĨ|ĘŽ|Ɲ|𝐡|𝐇|ⓗ|đ”Ĩ|ℌ|𝖍|đ•ŗ|𝓱|𝓗|đ’Ŋ|đģ|𝕙|ℍ|īŊˆ|🄷|ℋ|🅷|Ņ’|ԋ|ꮒ|ɧ|đ—ĩ|𝗛|𝘩|𝘏|𝙝|𝙃|𝚑|𝙷|卄|ん|Õ°|á•ŧ/g, 'h') .replace(/ƕ/g, 'hu') .replace(/ÉĒ|áĩĸ|á´ĩ|áļĻ|⁹|Κ|Äą|ɨ|áļ–|ᴉ|đĸ|𝐈|ⓘ|đ”Ļ|ℑ|𝖎|𝕴|𝓲|𝓘|𝒾|đŧ|𝕚|𝕀|īŊ‰|🄸|ę ¸|🅸|āš€|ę­ĩ|đ—ļ|𝗜|đ˜Ē|𝘐|𝙞|𝙄|𝚒|𝙸|丨|īž‰|ᓰ|áļ¤/g, 'i') .replace(/Äŗ/g, 'ij') .replace(/ᴊ|âąŧ|á´ļ|ʲ|ʝ|ɉ|ȡ|ɟ|đŖ|𝐉|ⓙ|𝔧|𝔍|𝖏|đ•ĩ|đ“ŗ|𝓙|đ’ŋ|đ’Ĩ|𝕛|𝕁|īŊŠ|🄹|ℐ|Ҙ|ę š|Õĩ|🅹|⏧|𝗷|𝗝|đ˜Ģ|𝘑|𝙟|𝙅|𝚓|𝙹|× |īžŒ|Ų„|ᒍ|ᒚ|Úļ|ᒎ/g, 'j') .replace(/ᴋ|Đē|ₖ|á´ˇ|áĩ|âąĒ|ꝃ|ƙ|ꝁ|ꝅ|áļ„|ʞ|𝐤|𝐊|ⓚ|𝔨|𝔎|𝖐|đ•ļ|𝓴|𝓚|𝓀|đ’Ļ|𝕜|𝕂|īŊ‹|đŸ„ē|Ō|ᛕ|đŸ…ē|Ķ„|ęŽļ|𝗸|𝗞|đ˜Ŧ|𝘒|𝙠|𝙆|𝚔|đ™ē|₭|゚|ԟ|á–Ŋᐸ|ŌĄ/g, 'k') .replace(/Ɵ|ᴌ|ₗ|á´¸|ËĄ|ℓ|⹥|ꝉ|ŀ|ł|ꞁ|ÉŦ|Č´|áļ…|É­|Åŋ|Éŋ|ן|đĨ|𝐋|⅃|ⓛ|𝔩|𝔏|𝖑|𝕷|đ“ĩ|𝓛|𝓁|đŋ|𝕝|𝕃|īŊŒ|đŸ„ģ|ℒ|áĨŖ|đŸ…ģ|ʅ|ꎭ|ÉŠ|𝗹|𝗟|𝘭|𝘓|𝙡|𝙇|𝚕|đ™ģ|ᄂ|ã„Ĩ|īžš|Ķ|á’Ē/g, 'l') .replace(/Į‰/g, 'lj') .replace(/ᴍ|Đŧ|ₘ|á´š|áĩ|Éą|áĩ¯|áļ†|ɰ|đĻ|𝐌|ⓜ|đ”Ē|𝔐|𝖒|𝕸|đ“ļ|𝓜|𝓂|𝑀|𝕞|𝕄|īŊ|đŸ„ŧ|â„ŗ|ᗰ|đŸ…ŧ|āš“|ꮇ|đ—ē|𝗠|𝘮|𝘔|đ™ĸ|𝙈|𝚖|đ™ŧ|â‚Ĩ|įˆĒ|īžļ|á˜ģ|Īģ/g, 'm') .replace(/É´|ₙ|á´ē|âŋ|ᴎ|и|ꞃ|ɲ|ƞ|Čĩ|áĩ°|áļ‡|Éŗ|ᴝ|𝐧|𝐍|ⓝ|đ”Ģ|𝔑|𝖓|𝕹|𝓷|𝓝|𝓃|𝒩|𝕟|ℕ|īŊŽ|đŸ„Ŋ|đŸ…Ŋ|⏠|Õŧ|ꮑ|ŋ|āē–|đ—ģ|𝗡|đ˜¯|𝘕|đ™Ŗ|𝙉|𝚗|đ™Ŋ|Đŋ|Ρ|â‚Ļ|几|刀|Õ˛|ហ|ᑎ|ᘉ|áļ°/g, 'n') .replace(/ĮŒ/g, 'nj') .replace(/ᴏ|ₒ|á´ŧ|áĩ’|΃|ꝋ|ꝍ|ø|ČŖ|âąē|ᴑ|ᴓ|𝐨|𝐎|ⓞ|đ”Ŧ|𝔒|𝖔|đ•ē|𝓸|𝓞|𝑜|đ’Ē|𝕠|𝕆|īŊ|ę­´|🄾|❀|āš|օ|ę­ˇ|āģ|đ—ŧ|đ—ĸ|𝘰|𝘖|𝙤|𝙊|𝚘|𝙾|ĶŠ|ð|ㄖ|ぎ|â™ĸ|āļ§|ᓍ|♡|đŸĩ|ᗝ|Îŋ|❁|☯/g, 'o') .replace(/ꝏ/g, 'oo') .replace(/Éļ|œ|ᴔ/g, 'oe') .replace(/ÆŖ/g, 'on') .replace(/ᴘ|ₚ|á´ž|áĩ–|΁|ꝓ|ÆĨ|ꝕ|áĩŊ|ꝑ|áĩą|áļˆ|𝐩|𝐏|ęŸŧ|ⓟ|𝔭|𝔓|𝖕|đ•ģ|𝓹|𝓟|𝓅|đ’Ģ|𝕡|ℙ|īŊ|đŸ„ŋ|℘|×§|ք|ę­ž|đ—Ŋ|đ—Ŗ|𝘱|𝘗|đ™Ĩ|𝙋|𝚙|đ™ŋ|Þ|₱|半|īŊą|Ά|ᑭ|á•ĩ/g, 'p') .replace(/ĮĢ|áĩŠ|áĩ |ꝙ|ꝗ|Ę |ɋ|đĒ|𝐐|ⓠ|𝔮|𝔔|𝖖|đ•ŧ|đ“ē|𝓠|𝓆|đ’Ŧ|đ•ĸ|ℚ|īŊ‘|🅀|𝑄|🆀|Ī™|ÕĻ|āš‘|𝗾|𝗤|𝘲|𝘘|đ™Ļ|𝙌|𝚚|𝚀|ゐ|ŌŠ|á‘Ģ|ᕴ/g, 'q') .replace(/ʀ|áĩŖ|á´ŋ|Ęŗ|ᴕ|ᴚ|ʁ|ᴙ|Ņ|ꞅ|ɍ|ÉŊ|Éž|Éŧ|áĩ˛|áļ‰|Éš|Éģ|Éē|âąš|ꎧ|đĢ|𝐑|ⓡ|đ”¯|ℜ|𝖗|đ•Ŋ|đ“ģ|𝓡|𝓇|𝑅|đ•Ŗ|ℝ|īŊ’|🅁|ℛ|ꭈ|🆁|Đŗ|ęŽĸ|āŊž|đ—ŋ|đ—Ĩ|đ˜ŗ|𝘙|𝙧|𝙍|𝚛|𝚁|å°ē|āŊ |ᖇ/g, 'r') .replace(/ꜱ|ₛ|Ëĸ|ʂ|áĩ´|áļŠ|Čŋ|ꝸ|đŦ|𝐒|â“ĸ|ꙅ|𝔰|𝔖|𝖘|𝕾|đ“ŧ|đ“ĸ|𝓈|𝒮|𝕤|𝕊|īŊ“|🅂|áĻ“|ę¯ą|🆂|⏪|ֆ|ęŽĨ|𝘀|đ—Ļ|𝘴|𝘚|𝙨|𝙎|𝚜|𝚂|ƨ|Ņ•|§|₴|丂|Ī›|ᔕ/g, 's') .replace(/īŦ†/g, 'st') .replace(/ᴛ|Ņ‚|ₜ|áĩ€|áĩ—|ƚ|ÉĢ|âąĻ|Æ­|ʈ|ŧ|Čļ|áĩĩ|ÆĢ|ʇ|𝐭|𝐓|â“Ŗ|𝔱|𝔗|𝖙|đ•ŋ|đ“Ŋ|đ“Ŗ|𝓉|đ’¯|đ•Ĩ|𝕋|īŊ”|🅃|𝑇|🆃|ęŽĻ|𝘁|𝗧|đ˜ĩ|𝘛|𝙩|𝙏|𝚝|𝚃|†|₮|ㄒ|īŊ˛|Õ§|Íŗ|á–ļ|丅/g, 't') .replace(/áĩē/g, 'th') .replace(/ꜩ/g, 'tz') .replace(/ᴜ|áĩ¤|áĩ|áĩ˜|ʋ|áļ™|𝐮|𝐔|ⓤ|𝔲|𝔘|𝖚|𝖀|𝓾|𝓤|𝓊|𝒰|đ•Ļ|𝕌|īŊ•|🅄|Ī…|🆄|ā¸ĸ|Ɗ|ęŽŧ|ꎰ|⏙|𝘂|𝗨|đ˜ļ|𝘜|đ™Ē|𝙐|𝚞|𝚄|҆|Âĩ|Îŧ|ʉ|ㄊ|ã˛|Õ´|ᑌ|ᑘ/g, 'u') .replace(/áĩĢ/g, 'ue') .replace(/á´ |áĩĨ|âąŊ|áĩ›|ÎŊ|ƌ|ꝟ|âą´|áļŒ|âąą|đ¯|𝐕|â“Ĩ|đ”ŗ|𝔙|𝖛|𝖁|đ“ŋ|đ“Ĩ|𝓋|𝒱|𝕧|𝕍|īŊ–|🅅|🆅|׊|ꮙ|Ûˇ|⏇|𝘃|𝗩|𝘷|𝘝|đ™Ģ|𝙑|𝚟|𝚅|ᐯ|√|Ņĩ|áģŊ|áē/g, 'v') .replace(/ꝡ/g, 'vy') .replace(/á´Ą|áĩ‚|ʡ|Ή|âąŗ|ʍ|ɯ|𝐰|𝐖|â“Ļ|𝔴|𝔚|𝖜|𝖂|𝔀|đ“Ļ|𝓌|𝒲|𝕨|𝕎|īŊ—|🅆|ā¸Ŧ|🆆|ÕĄ|ꮗ|āēŸ|𝘄|đ—Ē|𝘸|𝘞|đ™Ŧ|𝙒|𝚠|𝚆|҉|₩|åąą|Ⱊ|ᗯ|á˜ē/g, 'w') .replace(/·|ₓ|ËŖ|áļ|𝐱|𝐗|ⓧ|đ”ĩ|𝔛|𝖝|𝖃|𝔁|𝓧|𝓍|đ’ŗ|𝕩|𝕏|īŊ˜|🅇|🆇|א|ĶŊ|Ōŗ|𝘅|đ—Ģ|𝘹|𝘟|𝙭|𝙓|𝚡|𝚇|×|Ķŋ|乂|īž’|ჯ|᙭|Đļ|ጀ/g, 'x') .replace(/ʏ|áĩ§|ʸ|҇|Æ´|áģŋ|ɏ|ʎ|𝐲|𝐘|ⓨ|đ”ļ|𝔜|𝖞|𝖄|𝔂|𝓨|𝓎|𝒴|đ•Ē|𝕐|īŊ™|🅈|ⴘ|Ō¯|🆈|×Ĩ|ყ|ę­š|⏝|𝘆|đ—Ŧ|đ˜ē|𝘠|𝙮|𝙔|đšĸ|𝚈|҃|ÂĨ|ㄚ|īž˜|Õž|͌|á–ģ/g, 'y') .replace(/á´ĸ|áļģ|ęĢ|áĩš|âąŦ|ČĨ|Æļ|ʑ|áĩļ|áļŽ|ʐ|ɀ|đŗ|𝐙|ⓩ|𝔷|ℨ|𝖟|𝖅|𝔃|𝓩|𝓏|đ’ĩ|đ•Ģ|ℤ|īŊš|🅉|Æē|🆉|Õš|ፚ|āēŠ|𝘇|𝗭|đ˜ģ|𝘡|đ™¯|𝙕|đšŖ|𝚉|乙|ᘔ|ᗱ|Õˇ/g, 'z'); } exports.textToLatin = textToLatin; /** * For any given input text, reduce any repeating characters to a given maximum amount of repetitions. * * As an example, the input string: `"heeellllooooo"` becomes: `"heelloo"` if that number is 2, or * `"heeelllooo"` if that number is 3, or `helo` if that number is 1. * * For English, it is recommended to not use values lower than 2. If this preprocessing is used, make * sure that the bad words and allowed terms also feature at most the same number of repeated characters. * I.e. if using this with the number "2", there is no use of putting words like "helllo" on the lists. * @param inputText - The text from which to remove repeat characters. * @param maxAllowedCharsInSequence - The maximum number of characters in sequence (such as "aaa", "bbb", * ...) that are allowed to remain in the input string. `Recommended: 2 or 3`, depending on the language * of your input text. * @returns The input text with all repeat characters that occur more than the max amount in sequence * removed. * @throws If `maxAllowedCharsInSequence` is not an integer (such as 1.5) or if it is 0 or less. */ function reduceRepeatCharacters(inputText, maxAllowedCharsInSequence) { if (maxAllowedCharsInSequence === void 0) { maxAllowedCharsInSequence = 2; } if (!Number.isInteger(maxAllowedCharsInSequence) || maxAllowedCharsInSequence < 1) { throw new Error('reduceRepeatCharacters - maxAllowedCharsInSequence needs to be an integer that is larger than 0'); } // match any word character `(\w)`, then refer to the last match `\1` and check if it appears // n or more times `{n,}` (where n is maxAllowedCharsInSequence) // replace this with our matched character '$1' repeated n times // in normal regexp terms this would be `string.replace(/(\w)\1{2,}/g, '$1$1')` if `n = 2` var regexp = new RegExp('(\\w)\\1{' + maxAllowedCharsInSequence + ',}', 'g'); var replacementStr = '$1'.repeat(maxAllowedCharsInSequence); return inputText.replace(regexp, replacementStr); } exports.reduceRepeatCharacters = reduceRepeatCharacters; //# sourceMappingURL=input_preprocessor.js.map