Package Exports
- mutate-stream
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 (mutate-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mutate-stream
Object mutation pipelines for flow control
I think object mode streams are really handy for async flow control:
var stream = require('mutate-stream');
validate(req.body)
.pipe(sanitize())
.pipe(whatever())
.pipe(dbWrite)This module is a simple wrapper to eliminate boilerplate in a lot of my applications.
Installation
Download node at nodejs.org and install it, if you haven't already.
npm install mutate-stream --saveUsage
stream(<transform function>, [ optional flush function ]);
Pass in a transform function and an optional flush function. mutate-stream returns a a function that can take an optional data object parameter (to start your pipeline). This function in turn returns a stream.
Example:
var stream = require('mutate-stream');
function foo (obj, encoding, cb) { /* some transform */ }
function bar (obj, encoding, cb) { /* some transform */ }
var fooStream = stream(foo),
barStream = stream(bar);
fooStream({some: 'optional data'})
.pipe(barStream());
Tests
npm install
npm test
> mutate-stream@0.0.0 test /Users/mark/projects/mutate-stream
> node test/mutate-stream.js
TAP version 13
# wraps transform function
ok 1 should be equivalent
1..1
# tests 1
# pass 1
# ok
Dependencies
- through2: A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
Dev Dependencies
- stream-output: Get the result of a streams transform pipeline for your tests
- tape: tap-producing test harness for node and browsers
License
MIT