-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemoji-parser.js
More file actions
50 lines (41 loc) · 1.26 KB
/
emoji-parser.js
File metadata and controls
50 lines (41 loc) · 1.26 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
const fs = require('fs');
const path = require('path');
const parseEmojiLine = (line) => {
const parts = line.split(' ; ');
const u = parts[0].trim();
const rest = parts[1].split(' # ');
const e = rest[1].split(' ')[0].trim();
const n = rest[1].substring(e.length).trim();
const filecode = u.substring(2);
const shortcut = `:${n.toLowerCase().replace(/ /g, '_')}:`;
return {
u, // nicode,
e, // moji,
n, // ame,
};
};
const regex = /\s/;
const processFile = (fileName) => {
fs.readFile(fileName, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
return;
}
const lines = data.split('\n');
const emojis = lines.filter(line => line.trim() !== '').map(parseEmojiLine).filter(emoji => !regex.test(emoji.u))
const outputFileName = path.basename(fileName, path.extname(fileName)) + '.json';
fs.writeFile(outputFileName, JSON.stringify(emojis, null, 0), (err) => {
if (err) {
console.error(`Error writing to file: ${err}`);
} else {
console.log(`Output written to ${outputFileName}`);
}
});
});
};
const fileName = process.argv[2];
if (!fileName) {
console.log('Please provide a file name as an argument.');
process.exit(1);
}
processFile(fileName);