Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brian-gates/stream-transformer

A simple tool to transform streams via registered global or keyed handlers
https://github.com/brian-gates/stream-transformer

Last synced: 13 days ago
JSON representation

A simple tool to transform streams via registered global or keyed handlers

Awesome Lists containing this project

README

        

# stream-transformer [![Build Status](https://travis-ci.org/brian-gates/stream-transformer.png?branch=master)](https://travis-ci.org/brian-gates/stream-transformer) [![devDependency Status](https://david-dm.org/brian-gates/stream-transformer.png?theme=shields.io)](https://david-dm.org/brian-gates/stream-transformer.png#info=devDependencies)

A simple tool to transform streams via registered global or keyed handlers

## Basic Usage

``` js
var transformer = new StreamTransformer();
transformer.write({foo: 'bar'});
transformer.on('data', function (transformed) {
transformed.should.eql({foo: 'bar'});
});
transformer.on('end', done);
```

## Global Transformers
``` js
var transformer = new StreamTransformer();
transformer.register(function (data, done){
data.foo += '!';
done(data);
});
transformer.write({foo: 'bar'});
transformer.on('data', function (transformed){
transformed.should.eql({foo: 'bar!'});
});
transformer.on('end', done);
```

## Keyed Transformers

``` js
var transformer = new StreamTransformer();
transformer.register('foo', function (data, done){
data.foo += '!';
done(data);
});
transformer.write(['foo', {foo: 'bar'}]);
transformer.on('data', function (transformed){
transformed.should.eql({foo: 'bar!'});
});
transformer.on('end', done);
```

## Extended Transformers
``` js
var transformer = new StreamTransformer();
transformer.register('foo', function (data, done){
data.foo += '!';
done(data);
});
transformer.register('foo', function (data, done){
this._super(data, function (data){
data.foo += '1';
done(data);
})
});
transformer.write(['foo', {foo: 'bar'}]);
transformer.on('data', function (transformed){
transformed.should.eql({foo: 'bar!1'});
});
transformer.on('end', done);