-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 822 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 822 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
#!/usr/bin/env node
const JSONStream = require('JSONStream');
const es = require('event-stream');
const commandLineArgs = require('command-line-args');
const { newDictionary, objToDictionary, outputDictionary } = require('./lib/dict');
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: String }
];
const args = commandLineArgs(optionDefinitions);
const dict = newDictionary();
process.stdin.setEncoding('utf8');
process.stdin
.pipe(JSONStream.parse())
.pipe(es.mapSync(function (obj) {
objToDictionary(dict, obj);
dict.count++;
delete obj;
}))
// .pipe(JSONStream.stringify(false))
// .pipe(process.stdout);
process.stdin.on('end', () => {
// process.stdout.write( JSON.stringify(dict, null, 4) );
outputDictionary(dict);
process.stdout.write('\n');
process.exit(0);
});