Package Exports
- through2-get
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (through2-get) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
through2-get
This is a super thin wrapper around through2 that works like _.get
but for streams.
For when through2 is just too verbose 😉
IMPORTANT: If you return null
from your function, the stream will end there.
IMPORTANT: _.get can only be applied to object streams.
var get = require("through2-get");
var content = get('content');
// vs. with through2:
var content = through2(function (chunk, encoding, cb) {
this.push(_.get(chunk, 'content'));
return cb();
})
// Then use your get:
source.pipe(content).pipe(sink)
// Works like `_.get` meaning you can specify a path and a default value
var contentEach = get({excludeZBS: true}, 'content', '');
// vs. with through2:
var contentEach = through2(function (chunk, encoding, cb) {
var out = _.get(chunk, 'content', '');
if (out === '') return cb();
this.push(out);
return cb();
});
Differences from _.get
:
- Cannot insert
null
elements into the stream without aborting.
API
require("through2-get")([options,] path, [defaultValue])
Create a stream.Transform
instance with objectMode: true
defaulting to true that will call _.get(path, defaultValue)
on each stream object.
var Tx = require("through2-get").ctor([options,] path, [defaultValue])
Create a reusable stream.Transform
TYPE that can be called via new Tx
or Tx()
to create an instance.
Arguments
options
excludeZBS
(boolean): defaultstrue
.- all other through2 options.
path
(Array|string): The path of the property to get.[defaultValue]
(*): The value returned if the resolved value is undefined.