-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathparser.js
More file actions
executable file
·69 lines (52 loc) · 1.54 KB
/
parser.js
File metadata and controls
executable file
·69 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var https = require('https');
var fs = require('fs');
function download(url, callback) {
https.get(url, function(res) {
var data = "";
res.on('data', function (chunk) {
data += chunk;
});
res.on("end", function() {
callback(data);
});
}).on("error", function() {
callback(null);
});
}
var categories = {};
download('https://cdn.rawgit.com/github/gemoji/master/db/emoji.json', function(data) {
parse(data);
parse_categories();
});
function parse(data) {
const json = JSON.parse(data);
var string = 'public let emojiList: [String: String] = [\n'
json.forEach(function(item){
if (typeof item.aliases === "undefined"
|| typeof item.emoji === "undefined"
|| item.emoji == "undefined") {
return;
}
const itemString = ' "' + item.aliases[0] + '": "' + item.emoji + '",\n'
string = string + itemString
if (!categories[item.category]) {
categories[item.category] = []
}
categories[item.category].push(item.emoji);
})
string = string + ']'
fs.writeFileSync('../Sources/Emoji.swift', string);
};
function parse_categories() {
var string = 'public let emojiCategories: [String: [String]] = [\n'
Object.keys(categories).forEach(function(category) {
const emojis = categories[category].map(function(emoji) {
return '"' + emoji + '"';
}).join(",");
const itemString = ' "' + category + '": [' + emojis + '],\n'
string = string + itemString
});
string = string + ']'
fs.writeFileSync('../Sources/Categories.swift', string);
};