Created
April 2, 2018 03:04
-
-
Save mingliangguo/58df55735d65f2c625009702836685f2 to your computer and use it in GitHub Desktop.
emoji converter
This file contains hidden or 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
| // convert emoji character to unicode key sequences | |
| var getCode = emoji => emoji.split('').map(c => c.codePointAt(0).toString(16)).join('-'); | |
| var unifiedToEmoji = unified => { | |
| return unified | |
| .split('-') | |
| .map(hex => parseInt(hex, 16)) | |
| .map(hex => String.fromCodePoint(hex)) | |
| .join(''); | |
| }; | |
| const unifiedToEmoji = unified => { | |
| const code = unified | |
| .split('-') | |
| .map(hex => parseInt(hex, 16)) | |
| // some how the character in the derived emojis are not standard, | |
| // it has to discard the 0xfe0f character so we can match with | |
| // emojis from emoji-data | |
| .filter(hex => hex !== 0xfe0f); | |
| return punycode.ucs2.encode(code); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment