|
|
@ -1,13 +1,38 @@ |
|
|
|
// @preval
|
|
|
|
// Force tree shaking on emojione by exposing just a subset of its functionality
|
|
|
|
// http://www.unicode.org/Public/emoji/5.0/emoji-test.txt
|
|
|
|
|
|
|
|
const emojione = require('emojione'); |
|
|
|
const emojis = require('./emoji_map.json'); |
|
|
|
const { emojiIndex } = require('emoji-mart'); |
|
|
|
const excluded = ['®', '©', '™']; |
|
|
|
const skins = ['🏻', '🏼', '🏽', '🏾', '🏿']; |
|
|
|
const shortcodeMap = {}; |
|
|
|
|
|
|
|
const mappedUnicode = emojione.mapUnicodeToShort(); |
|
|
|
const excluded = ['®', '©', '™']; |
|
|
|
Object.keys(emojiIndex.emojis).forEach(key => { |
|
|
|
shortcodeMap[emojiIndex.emojis[key].native] = emojiIndex.emojis[key].id; |
|
|
|
}); |
|
|
|
|
|
|
|
module.exports.unicodeMapping = Object.keys(emojione.jsEscapeMap) |
|
|
|
.filter(c => !excluded.includes(c)) |
|
|
|
.map(unicodeStr => [unicodeStr, mappedUnicode[emojione.jsEscapeMap[unicodeStr]]]) |
|
|
|
.map(([unicodeStr, shortCode]) => ({ [unicodeStr]: [emojione.emojioneList[shortCode].fname.replace(/^0+/g, ''), shortCode.slice(1, shortCode.length - 1)] })) |
|
|
|
.reduce((x, y) => Object.assign(x, y), { }); |
|
|
|
const stripModifiers = unicode => { |
|
|
|
skins.forEach(tone => { |
|
|
|
unicode = unicode.replace(tone, ''); |
|
|
|
}); |
|
|
|
|
|
|
|
return unicode; |
|
|
|
}; |
|
|
|
|
|
|
|
Object.keys(emojis).forEach(key => { |
|
|
|
if (excluded.includes(key)) { |
|
|
|
delete emojis[key]; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const normalizedKey = stripModifiers(key); |
|
|
|
let shortcode = shortcodeMap[normalizedKey]; |
|
|
|
|
|
|
|
if (!shortcode) { |
|
|
|
shortcode = shortcodeMap[normalizedKey + '\uFE0F']; |
|
|
|
} |
|
|
|
|
|
|
|
emojis[key] = [emojis[key], shortcode]; |
|
|
|
}); |
|
|
|
|
|
|
|
module.exports.unicodeMapping = emojis; |