Skip to content

Instantly share code, notes, and snippets.

@mingliangguo
Created April 2, 2018 03:04
Show Gist options
  • Select an option

  • Save mingliangguo/58df55735d65f2c625009702836685f2 to your computer and use it in GitHub Desktop.

Select an option

Save mingliangguo/58df55735d65f2c625009702836685f2 to your computer and use it in GitHub Desktop.
emoji converter
// 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