/
generate-data-tables.js
155 lines (141 loc) · 5.46 KB
/
generate-data-tables.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const fs = require('fs');
const _ = require('lodash');
const csvWriter = require('csv-write-stream');
const csvParse = require('csv-parse/lib/sync');
const emojibaseData = require('emojibase-data/en/data.json');
const emojibaseGroups = require('emojibase-data/meta/groups.json');
const groups = emojibaseGroups.groups;
const subgroups = emojibaseGroups.subgroups;
// -- helper functions --
const loadCsv = (filePath) => {
const content = fs.readFileSync(filePath, 'utf8');
return csvParse(content, {columns: true});
}
const arrayToEmojiDict = (array) => {
return array.reduce((o, a) => Object.assign(o, { [a.emoji]: a }), {});
}
const writeCsv = (data, filePath) => {
const csvOut = csvWriter();
csvOut.pipe(fs.createWriteStream(filePath));
for (d of data) csvOut.write(d);
csvOut.end();
}
const writeJson = (data, filePath) => {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
}
// -- create emoji tables --
// create an empty array to hold the emoji definitions
let emojis = [];
// add emoji with skintones to list
_.each(emojibaseData, e => {
if (e.skins) {
e['skintone_base_emoji'] = e.emoji;
e['skintone_base_hexcode'] = e.hexcode;
e['skintone_combination'] = 'single';
// add skintone_base_emoji prop
const skintones = _.map(e.skins, (s) => {
s['skintone_base_emoji'] = e.emoji;
s['skintone_base_hexcode'] = e.hexcode;
if (_.isArray(s.tone)) {
// console.warn(`Warning: ${s.emoji} ${s.hexcode} is a multi skin tones combination`);
s.tone = s.tone.join(',');
s['skintone_combination'] = 'multiple';
} else {
s['skintone_combination'] = 'single';
}
return s;
})
emojis = [...emojis, ...skintones];
}
emojis = [...emojis, e];
});
// load custom meta informations extending the unicode definitions
const enhancements = arrayToEmojiDict( loadCsv('./data/enhancements-emoji-unicode-data.csv'), 'emoji');
// filter out what we want in the end
// enhance meta informations of each emoji
emojis = _.map(emojis, e => {
let openmoji_author = enhancements[e.emoji] ? enhancements[e.emoji]['openmoji_author'] : '';
let openmoji_date = enhancements[e.emoji] ? enhancements[e.emoji]['openmoji_date'] : '';
if (e.skintone_base_emoji) {
openmoji_author = enhancements[e.skintone_base_emoji] ? enhancements[e.skintone_base_emoji]['openmoji_author'] : '';
openmoji_date = enhancements[e.skintone_base_emoji] ? enhancements[e.skintone_base_emoji]['openmoji_date'] : '';
}
return {
emoji: e.emoji,
hexcode: e.hexcode,
group: groups[e.group],
subgroups: subgroups[e.subgroup],
annotation: e.annotation,
tags: e.tags ? e.tags.join(', ') : '',
openmoji_tags: enhancements[e.emoji] ? enhancements[e.emoji]['openmoji_tags'] : '',
openmoji_author: openmoji_author,
openmoji_date: openmoji_date,
skintone: e.tone ? e.tone : '',
skintone_combination: e.skintone_combination ? e.skintone_combination : '',
skintone_base_emoji: e.skintone_base_emoji ? e.skintone_base_emoji : '',
skintone_base_hexcode: e.skintone_base_hexcode ? e.skintone_base_hexcode : '',
unicode: e.version,
order: e.order,
};
});
// sort by recommended order of unicode standard
emojis = _.orderBy(emojis, ['order', 'group', 'subgroups', 'hexcode'], ['asc', 'asc', 'asc', 'asc']);
// -- save to CSV and JSON files --
// writeJson(emojis, 'data/openmoji-emoji12.json');
// writeCsv(emojis, 'data/openmoji-emoji12.csv');
// select all emojis which have not been designed yet (without skintones)
const missingEmojis = _.filter(emojis, (e) => { return e.openmoji_author === '' && e.skintone === '' });
if (missingEmojis.length > 0) {
writeCsv(missingEmojis, 'data/openmoji-emoji-unicode-missing.csv');
}
// remove all emojis which have not been designed yet
emojis = _.filter(emojis, (e) => { return e.openmoji_author !== '' });
// add extras
let extrasOpenMoji = loadCsv('./data/extras-openmoji.csv');
extrasOpenMoji = _.map(extrasOpenMoji, e => {
const codePoint = parseInt(e.hexcode, 16);
return {
// image: `=IMAGE("https://github.com/hfg-gmuend/openmoji/blob/v1.5/color/72x72/${e.hexcode +'.png?raw=true'}")`,
emoji: codePoint ? String.fromCodePoint(codePoint) : '',
hexcode: e.hexcode,
group: e.group,
subgroups: e.subgroups,
annotation: e.annotation,
tags: '',
openmoji_tags: e.openmoji_tags,
openmoji_author: e.openmoji_author,
openmoji_date: e.openmoji_date,
skintone: '',
skintone_combination: '',
skintone_base_emoji: '',
skintone_base_hexcode: '',
unicode: '',
order: '',
};
});
let extrasUnicode = loadCsv('./data/extras-unicode.csv');
extrasUnicode = _.map(extrasUnicode, e => {
return {
emoji: String.fromCodePoint(parseInt(e.hexcode, 16)),
hexcode: e.hexcode,
group: e.group,
subgroups: e.subgroups,
annotation: e.annotation,
tags: '',
openmoji_tags: e.openmoji_tags,
openmoji_author: e.openmoji_author,
openmoji_date: e.openmoji_date,
skintone: '',
skintone_combination: '',
skintone_base_emoji: '',
skintone_base_hexcode: '',
unicode: e.unicode,
order: '',
};
});
extrasOpenMoji = _.orderBy(extrasOpenMoji, ['order', 'group', 'subgroups', 'hexcode'], ['asc', 'asc', 'asc', 'asc']);
extrasUnicode = _.orderBy(extrasUnicode, ['order', 'group', 'subgroups', 'hexcode'], ['asc', 'asc', 'asc', 'asc']);
emojis = [...emojis, ...extrasOpenMoji, ...extrasUnicode];
// -- save to CSV and JSON files --
writeJson(emojis, 'data/openmoji.json');
writeCsv(emojis, 'data/openmoji.csv');