diff options
author | mat <github@matdoes.dev> | 2022-02-15 22:11:07 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-02-15 22:11:07 +0000 |
commit | 77679dbf69ae097cefbbcabe9c2b952d446e9677 (patch) | |
tree | 50638e0247a7fe9131c6989124ad67f39e99aa40 /src/lib/utils.ts | |
parent | c060d60ba1d5f3ad9f37b48b50b694a2d19240d1 (diff) | |
download | skyblock-stats-77679dbf69ae097cefbbcabe9c2b952d446e9677.tar.gz skyblock-stats-77679dbf69ae097cefbbcabe9c2b952d446e9677.tar.bz2 skyblock-stats-77679dbf69ae097cefbbcabe9c2b952d446e9677.zip |
add username in profile
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r-- | src/lib/utils.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 5d8ecc8..f93f68e 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -120,4 +120,16 @@ export function shuffle<T>(a: T[]): T[] { ;[a[i], a[j]] = [a[j], a[i]] } return a +} + +const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g + + +export function twemojiHtml(s: string) { + const htmlEncoded = s.replace('<', '<').replace('>', '>').replace('&', '&') + // replace unicode emojis with <img src="/emoji/[hex].svg"> + const asTwemoji = htmlEncoded.replace(emojiRegex, (match) => { + return `<img src="/emoji/${[...match].map(p => p.codePointAt(0).toString(16)).join('-')}.svg" class="emoji">` + }) + return asTwemoji }
\ No newline at end of file |