hardlounge/scripts/generate-emoji.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
2019-04-15 16:19:50 +00:00
const got = require("got");
const path = require("path");
const fs = require("fs");
// same regex as found in client/../parse.js
const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]|\u{fe0f}/gu;
2019-04-15 16:19:50 +00:00
(async () => {
2019-07-17 09:33:59 +00:00
const response = await got(
"https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
);
2019-04-15 16:19:50 +00:00
const emojiStrategy = JSON.parse(response.body);
const emojiMap = {};
2018-03-09 22:00:16 +00:00
const fullNameEmojiMap = {};
2019-06-10 19:14:11 +00:00
for (const emoji of emojiStrategy) {
const cleanEmoji = emoji.emoji.replace(emojiModifiersRegex, "");
fullNameEmojiMap[cleanEmoji] = emoji.description;
2019-06-10 19:14:11 +00:00
for (const alias of emoji.aliases) {
emojiMap[alias] = emoji.emoji;
}
}
2018-03-09 22:00:16 +00:00
const emojiMapOutput = JSON.stringify(emojiMap, null, 2) + "\n";
const fullNameEmojiMapOutput = JSON.stringify(fullNameEmojiMap, null, 2) + "\n";
2019-07-17 09:33:59 +00:00
fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "simplemap.json")),
2019-07-17 09:33:59 +00:00
emojiMapOutput
);
2018-03-09 22:00:16 +00:00
2019-07-17 09:33:59 +00:00
fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "fullnamemap.json")),
2019-07-17 09:33:59 +00:00
fullNameEmojiMapOutput
);
2019-04-15 16:19:50 +00:00
})();