-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
41 lines (32 loc) · 1019 Bytes
/
build.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
'use strict';
var _ = require('lodash'), fs = require('fs'), table = require('text-table');
var READ_UTF8 = {mode: 'r', encoding: 'utf8'};
var kanjiKeys = JSON.parse(fs.readFileSync('./kanji-keys.json', READ_UTF8));
var nonUniq = _.chain(kanjiKeys)
.keys()
.groupBy(function (char) {
return kanjiKeys[char].uniq;
})
.pairs()
.filter(function (row) {
return row[1].length > 1;
})
.value();
if (nonUniq.length > 0) {
console.error('Some kanji have non-unique keys:');
console.error(nonUniq.map(function (row) {
return row[0] + ':' + row[1].join('');
}).join('\n'));
}
var tableRows = _.chain(kanjiKeys)
.pairs()
.map(function (pair, index) {
return [index + 1, pair[0], pair[1].uniq, pair[1].keys.join(', ')];
})
.value();
var header = [
['no.', 'kanji', 'unique key', 'other keys'],
['---', '-----', '----------', '----------']
];
var tableOpts = { hsep: ' | ' };
fs.writeFileSync('kanji-keys.md', table(header, tableOpts) + '\n' + table(tableRows, tableOpts));