-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-output.js
45 lines (45 loc) · 1 KB
/
create-output.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
var stream = require('readable-stream')
var Transform = stream.Transform;
var PassThrough = stream.PassThrough
var sanatize = require('./sanatize');
class Output extends Transform {
constructor(copy) {
super({objectMode: true});
this.i = 0;
this.copy = copy;
this.sanCache = new Map();
}
sanatize(key) {
if (this.sanCache.has(key)) {
return this.sanCache.get(key)
}
let out = sanatize(key);
this.sanCache.set(key, out);
return out;
}
fixProps(oldProps) {
var out = {};
var keys = Object.keys(oldProps);
var i = -1;
var key;
while (++i < keys.length) {
key = keys[i];
out[this.sanatize(key)] = oldProps[key];
}
return out;
}
_transform(chunk, _, next) {
chunk.properties = this.fixProps(chunk.properties)
if (this.copy) {
this.i++;
if (!(this.i%100)) {
this.emit('inserted', this.i);
}
}
this.push(chunk);
next();
}
}
module.exports = function (copy) {
return new Output(copy)
}