thelounge/scripts/generate-emoji.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

"use strict";
2019-04-15 18:19:50 +02: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 18:19:50 +02:00
(async () => {
2019-07-17 11:33:59 +02:00
const response = await got(
"https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json"
);
2019-04-15 18:19:50 +02:00
const emojiStrategy = JSON.parse(response.body);
const emojiMap = {};
2018-03-09 23:00:16 +01:00
const fullNameEmojiMap = {};
2019-06-10 21:14:11 +02:00
for (const emoji of emojiStrategy) {
const cleanEmoji = emoji.emoji.replace(emojiModifiersRegex, "");
fullNameEmojiMap[cleanEmoji] = emoji.description;
for (let alias of emoji.aliases) {
if (alias !== "-1") {
// Replace dashes to underscores except for :-1:
// This removes autocompletion prompt for :-P
// prompting for :non-potable_water:
alias = alias.replace(/-/g, "_");
}
2019-06-10 21:14:11 +02:00
emojiMap[alias] = emoji.emoji;
}
}
2018-03-09 23:00:16 +01:00
const emojiMapOutput = JSON.stringify(emojiMap, null, 2) + "\n";
const fullNameEmojiMapOutput = JSON.stringify(fullNameEmojiMap, null, 2) + "\n";
2019-07-17 11:33:59 +02:00
fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "simplemap.json")),
2019-07-17 11:33:59 +02:00
emojiMapOutput
);
2018-03-09 23:00:16 +01:00
2019-07-17 11:33:59 +02:00
fs.writeFileSync(
path.resolve(path.join(__dirname, "..", "client", "js", "helpers", "fullnamemap.json")),
2019-07-17 11:33:59 +02:00
fullNameEmojiMapOutput
);
2019-04-15 18:19:50 +02:00
})();