through2-get

1.0.0 • Public • Published

through2-get

Version License Test Coverage Status

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): defaults true.
    • all other through2 options.
  • path (Array|string): The path of the property to get.
  • [defaultValue] (*): The value returned if the resolved value is undefined.

Package Sidebar

Install

npm i through2-get

Weekly Downloads

2,125

Version

1.0.0

License

MIT

Unpacked Size

6.54 kB

Total Files

6

Last publish

Collaborators

  • jramsay