/**
* https://www.npmjs.com/package/escape-string-regexp
*/
export const sanitizeForRegex = (unsafeText: string): string =>
unsafeText.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
export const HTTP_URL_PATTERN = `https?:\\/\\/(?:www\\.)?(?:[^\\s)]*)(?()[\]\\.,;:\s@\\"]+(\.[^<>()[\]\\.,;:\s@\\"]+)*)|(\\".+\\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
export const URL_NEG_LB = '(?)*((?:
]*\bdata-mx-emoticon\b[^>]*\/?>)(?:\s|
)*){1,10}$/i;
/**
* True when a message is emoji/custom-emote only (Discord-style jumbo).
* Strips zero-width chars and also accepts HTML that is only mx-emoticon imgs.
*/
export const isJumboEmoji = (body: string, customBody?: string): boolean => {
const plain = body.replace(JUMBO_IGNORE_CHARS_REG, '').trim();
if (plain.length > 0 && JUMBO_EMOJI_REG.test(plain)) return true;
if (typeof customBody === 'string') {
const html = customBody
.replace(JUMBO_IGNORE_CHARS_REG, '')
.trim()
.replace(/(
\s*)+$/gi, '');
if (html.length > 0 && ONLY_MX_EMOTICON_HTML_REG.test(html)) return true;
}
return false;
};