-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
40 lines (36 loc) · 855 Bytes
/
parser.js
File metadata and controls
40 lines (36 loc) · 855 Bytes
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
var fs = require('fs');
var codeMap = new Map();
var nameMap = new Map();
function readUCDLines (cb) {
fs.readFile('UnicodeData.txt', 'ascii', function (err, data) {
if (err) {
cb(err);
} else {
cb(null, data.split('\n'));
}
});
}
function loadIndexes(cb) {
readUCDLines(function (err, data) {
if (err) {
cb(err);
} else {
data.forEach(function (line) {
var parts = line.split(';');
if (parts[1] && !parts[1].startsWith('<')) {
codeMap.set(parts[0], parts[1]);
parts[1].split(' ').forEach(function(word) {
nameMap.set(word, (nameMap.get(word) || new Set()).add(parts[0]));
});
}
});
cb();
}
});
}
module.exports = {
readUCDLines: readUCDLines,
loadIndexes: loadIndexes,
codeMap: codeMap,
nameMap: nameMap,
};