0.0.3 • Published 8 years ago

ulmo v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

ulmo

Ulmo is a set of stream utility functions.

Unless otherwise noted, ulmo streams:

  • operate in objectMode
  • expect decoded strings (rather than un-encoded Buffers)

API

append(array) => Transform

Create transform stream to inject values at end of input.

// inject newline and 'foo' after the input
stream.pipe(append(["\n", "foo"]));

concat() => Transform

Create transformation to concatenate contiguous string data.

stream.pipe(concat());

filter(function) => Transform

Create transform stream from a filter function. All chunks are passed through the filter function, and only those chunks which match the filter are written to the output.

// filter out non-string data
stream.pipe(filter(s => typeof s === "string"));

map(function) => Transform

Create transform stream from a map function. All chunks are passed through the map function before being written to the output.

// add ordinal to input object chunks
var i = 0;
stream.pipe(map(o => Object.assign(o, {ordinal: ++i})));

partialMap(function, function) => Transform

Create transform stream by passing through chunks which don't match a filter function, and passing matching chunks through a map function.

// uppercase all string input, and pass through non-string input
stream.pipe(partialMap(s => typeof s === "string", s.toUpperCase()));

prepend(array) => Transform

Create transform stream to inject values at beginning of input.

// inject 'foo' and newline before the input
stream.pipe(prepend(["foo", "\n"]));

transform(function) => Transform

Functional wrapper to create a transform stream. The transform function receives two arguments: the chunk and a continuation function which must be called when processing of the chunk has completed. Inside the transform, this.push can be used to write chunks to the output. Unlike the standard library Transform function, no encoding is passed to the transform function.

// uppercase all string input, and pass through non-string input
stream.pipe(transform(function(chunk, done) {
    this.push(typeof chunk === "string" ? chunk.toUpperCase() : chunk);
}));