-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-emoji-lists.js
108 lines (79 loc) · 2.03 KB
/
merge-emoji-lists.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
var fs = require('fs');
var path = require('path');
var _ = require('underscore');
var files = setup([
'./assets/emoji-names.txt',
'./assets/emoji-find-replace.txt',
'./assets/emoji-character-picker.txt'
]);
var emojis = merge(files);
var formatted = format(emojis);
fs.writeFileSync(path.resolve(__dirname, './assets/emoji-fuse-list.json'), JSON.stringify(formatted), 'utf8');
console.log('Finished');
function format(emojis) {
var result = [];
for (var name in emojis) {
var keywords = emojis[name];
var wordlist = [];
keywords = _.uniq(keywords.split(' | '));
wordlist = keywords;
// for (var j = 0; j < keywords.length; j++) {
// var keyword = keywords[j].toLowerCase();
// var words = keyword.split(/\s/i);
// wordlist = wordlist.concat(words);
// }
result.push({
emoji: name,
keywords: _.uniq(wordlist)
});
}
console.log(result);
return result;
}
function merge(files) {
var amount = files[0].length;
var result = {};
for (var i = 0; i < files.length; i++) {
var list = files[i];
for (var j = 0; j < list.length; j++) {
var item = list[j];
var emoji = item[0];
var text = item[1];
if (emoji in result) {
result[emoji] += ' | ' + text;
} else {
result[emoji] = text;
}
}
}
return result;
}
function setup(files) {
var result = [];
for (var i = 0; i < files.length; i++) {
var filename = files[i];
var list = fs.readFileSync(path.resolve(__dirname, filename), {
encoding: 'utf-8'
});
console.log('Setup', filename);
list = massage(list);
result.push(list);
}
return result;
}
function massage(text) {
var result = text.split('\n');
for (var i = 0; i < result.length; i++) {
var line = result[i];
var index = line.indexOf(' ');
if (index >= 0) {
result[i] = [
line.slice(0, index + 1).replace(/\s/, ''),
line.slice(index).replace(/^\s/, '')
];
} else {
result[i] = [line];
}
}
return result;
}