import twemoji from "twemoji"; export function parseEmoji(text: string) { return twemoji .parse(text, { folder: "svg", ext: ".svg", }) .replaceAll( "twemoji.maxcdn.com/v", "cdnjs.cloudflare.com/ajax/libs/twemoji" ); } const URL_REGEX = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi; const ACCOUNT_REGEX = /(^|[^@\w])@(\w{1,15})\b/g; const HASHTAG_REGEX = /(^|\B)#(?![0-9_]+\b)([a-zA-Z0-9_]{1,30})(\b|\r)/g; export function twitterAutoLink(text: string) { return text .replace(URL_REGEX, (url: string) => { return `${url}`; }) .replace(HASHTAG_REGEX, (hashTag, _, name) => { return `${hashTag}`; }) .replace(ACCOUNT_REGEX, (account, _, name) => { return `${account}`; }); }