2017-10-19 09:36:53 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-04-15 16:19:50 +00:00
|
|
|
const got = require("got");
|
2017-10-19 09:36:53 +00:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
|
|
|
const fuzzy = require("fuzzy");
|
|
|
|
|
2019-04-15 16:19:50 +00:00
|
|
|
(async () => {
|
|
|
|
const response = await got("https://raw.githubusercontent.com/emojione/emojione/master/extras/alpha-codes/eac.json");
|
|
|
|
const emojiStrategy = JSON.parse(response.body);
|
2017-10-19 09:36:53 +00:00
|
|
|
const emojiMap = {};
|
2018-03-09 22:00:16 +00:00
|
|
|
const fullNameEmojiMap = {};
|
2017-10-19 09:36:53 +00:00
|
|
|
|
|
|
|
for (const key in emojiStrategy) {
|
|
|
|
if (emojiStrategy.hasOwnProperty(key)) {
|
2018-08-31 19:41:41 +00:00
|
|
|
const shortname = prepareShortName(emojiStrategy[key].alpha_code);
|
|
|
|
const unicode = stringToUnicode(emojiStrategy[key].output);
|
2018-03-09 22:00:16 +00:00
|
|
|
fullNameEmojiMap[unicode] = emojiStrategy[key].name;
|
2017-10-19 09:36:53 +00:00
|
|
|
|
|
|
|
// Skip tones, at least for now
|
2017-11-22 06:39:32 +00:00
|
|
|
if (shortname.includes("tone")) {
|
2017-10-19 09:36:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
emojiMap[shortname] = unicode;
|
|
|
|
|
2018-08-31 19:41:41 +00:00
|
|
|
for (let alternative of emojiStrategy[key].aliases.split("|")) {
|
2017-10-19 09:36:53 +00:00
|
|
|
alternative = prepareShortName(alternative);
|
|
|
|
|
|
|
|
if (fuzzy.test(shortname, alternative) || fuzzy.test(alternative, shortname)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
emojiMap[alternative] = unicode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:00:16 +00:00
|
|
|
const emojiMapOutput = JSON.stringify(emojiMap, null, 2) + "\n";
|
|
|
|
const fullNameEmojiMapOutput = JSON.stringify(fullNameEmojiMap, null, 2) + "\n";
|
2017-10-19 09:36:53 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(path.resolve(path.join(
|
|
|
|
__dirname,
|
|
|
|
"..",
|
|
|
|
"client",
|
|
|
|
"js",
|
|
|
|
"libs",
|
|
|
|
"simplemap.json"
|
2018-03-09 22:00:16 +00:00
|
|
|
)), emojiMapOutput);
|
|
|
|
|
|
|
|
fs.writeFileSync(path.resolve(path.join(
|
|
|
|
__dirname,
|
|
|
|
"..",
|
|
|
|
"client",
|
|
|
|
"js",
|
|
|
|
"libs",
|
|
|
|
"fullnamemap.json"
|
|
|
|
)), fullNameEmojiMapOutput);
|
2019-04-15 16:19:50 +00:00
|
|
|
})();
|
2017-10-19 09:36:53 +00:00
|
|
|
|
|
|
|
function stringToUnicode(key) {
|
|
|
|
return key
|
|
|
|
.split("-")
|
|
|
|
.map((c) => String.fromCodePoint(`0x${c}`))
|
|
|
|
.join("");
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareShortName(shortname) {
|
|
|
|
if (shortname === ":-1:") {
|
|
|
|
// We replace dashes, but should keep :-1: working
|
|
|
|
return "-1";
|
|
|
|
} else if (shortname === ":e-mail:") {
|
|
|
|
// :email: exists as an alternative, should figure out how to use it instead
|
|
|
|
return "email";
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortname
|
|
|
|
.slice(1, -1)
|
|
|
|
.replace("-", "_");
|
|
|
|
}
|