concat-stream + JSON.parse + callback interface and custom parsers
npm install parse-concat-stream
[travis-badge]: https://travis-ci.org/eush77/parse-concat-stream.svg
[travis]: https://travis-ci.org/eush77/parse-concat-stream
[david-badge]: https://david-dm.org/eush77/parse-concat-stream.png
[david]: https://david-dm.org/eush77/parse-concat-stream
[david-dev-badge]: https://david-dm.org/eush77/parse-concat-stream/dev-status.png
[david-dev]: https://david-dm.org/eush77/parse-concat-stream#info=devDependencies
The simplest possible combination of concat-stream and native JSON.parse. It provides callback interface just like concat-stream does and accepts custom parser functions.
``js`
> stread('{ "foo": 1, "bar": [2, 3] }')
.pipe(parseConcat(function (err, data) {
if (err) throw err;
console.log(JSON.stringify(data, null, 1));
}));
{
"foo": 1,
"bar": [
2,
3
]
}
Custom parser:
`js`
> var caps = function (string) {
return (string.match(/[A-Z]/g) || []).join('').toLowerCase();
};
> stread(' {\nMEdiS]]\n} SorAs \tGEt')
.pipe(parseConcat({ parse: caps }, function (err, data) {
if (err) throw err;
console.log(JSON.stringify(data));
}));
"message"
Return a writable stream, run cb once it closes.
data is JSON.parsed by default, unless custom opts.parse is provided.
null is a shorthand for the identity function, so that``
parseConcat({ parse: null }, cb);`
is equivalent to`
require('concat-stream')({ encoding: 'string' }, cb.bind(null, null));
| Option | Type | Required? | Default |
| :------| :--------------- | :-------: | :----------- |
| parse | function(string) | No | JSON.parse |
`shell``
npm install parse-concat-stream
MIT