Skip to content

Commit 5b2f79b

Browse files
committed
Jsonify converts an object stream to a stream of JSON
1 parent 44863b9 commit 5b2f79b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

basic.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ var lexer = new Lexer();
44
var parser = new Parser();
55
var generator = new Generator();
66

7+
var Jsonify = require('./jsonify');
8+
var jsonify = new Jsonify();
9+
10+
// lexer.pipe(jsonify).pipe(process.stderr);
11+
// parser.pipe(jsonify).pipe(process.stderr);
12+
713
process.stdin
814
.pipe(lexer)
915
.pipe(parser)

jsonify.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = Debug;
2+
var util = require('util'), stream = require('stream');
3+
util.inherits(module.exports, stream.Transform);
4+
function Debug(options) {
5+
stream.Transform.call(this, options);
6+
this._writableState.objectMode = true;
7+
this._readableState.objectMode = false;
8+
}
9+
Debug.prototype._transform = function(chunk, encoding, cb) {
10+
this.push(JSON.stringify(chunk, null, '\t'));
11+
this.push('\n');
12+
cb();
13+
};
14+

0 commit comments

Comments
 (0)