Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/brian-gates/stream-transformer
- Owner: brian-gates
- Created: 2014-01-29T18:48:17.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-30T20:08:55.000Z (almost 11 years ago)
- Last Synced: 2024-12-07T21:58:07.260Z (about 1 month ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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);