1 | ;
|
2 |
|
3 | var through = require('through');
|
4 |
|
5 | var formatStream = module.exports = function (indent) {
|
6 | var data = '';
|
7 | return through(ondata, onend);
|
8 |
|
9 | function ondata(d) {
|
10 | data += d;
|
11 | }
|
12 |
|
13 | function onend() {
|
14 | try {
|
15 | var json = JSON.parse(data);
|
16 | this.queue(JSON.stringify(json, null, indent || 2));
|
17 | } catch (e) {
|
18 |
|
19 | this.queue(e.toString());
|
20 | }
|
21 | this.emit('end');
|
22 | }
|
23 | };
|
24 |
|