Last active
June 3, 2023 22:37
-
-
Save KrisKnez/116a7e27cdeaf09b25373fecb8d322f7 to your computer and use it in GitHub Desktop.
JS Emoji utilities
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
// https://ihateregex.io/expr/emoji/ | |
export const emojiRegExpString = | |
'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])' | |
export const emojiToUnified = (emoji: string) => | |
[...emoji].map((e) => e.codePointAt(0)?.toString(16)).join('-') | |
export const unifiedRegExpString = '\b([da-fA-F]{4,5}|[da-fA-F]{6}|[da-fA-F]{8})\b' | |
export const unifiedToEmoji = (unified: string) => | |
String.fromCodePoint(...unified.split('-').map((c) => parseInt(c, 16))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment