/* jshint esversion: 6 */

const fs = require('fs');

var inputData = JSON.parse(fs.readFileSync(__dirname +"/emoji.json").toString("UTF-8"));
var result = [];

function unDot(str) {
    if (str[0] === ':' && str[str.length -1] === ':')
        return str.substr(1, str.length -2);
    return str;
}

var categories = {};

for (var i in inputData) {
    var item = {
        names: [],
        keywords: inputData[i].keywords,
        unicode: i,
        sprite: inputData[i].category
    },
    shortName = unDot(inputData[i].shortname);
        categories[item.sprite] = true;

    var aliases = inputData[i].shortname_alternates;
    for (var aliasIndex =0, nbAliases = aliases.length; aliasIndex < nbAliases; aliasIndex++)
        item.names.push(unDot(aliases[aliasIndex]));
    if (shortName.substr(0, 4) === 'flag')
        item.names.unshift(shortName);
    else
        item.names.push(shortName);
    result.push(item);
}

console.log("/** @const */ var emojis=" +JSON.stringify(result) +';');

