mutate

Object transformations implementing the Node.js stream.Transform API

This project provide object transformation. It implements the latest stream Transform api. While developed as a part of the Node.js CSV module (npm install csv), it could be used indepently.

Documentation for the mutate module is available here.

  • Fully Node.js compliant, pipe through it
  • Run sequentially or in parallel with a define number of callbacks
  • Accept object, array or JSON as input and output

Installation command is npm install mutate.

You may run this script with the command node samples/sync.js. Note how the use callback is only requesting one argument, the data to mutate.

var mutate = require('mutate');
mutate()
.parallel(20)
.use(function(data){
  data.push(data.shift())
})
.write( ['1','2','3','4'] )
.write( ['a','b','c','d'] )
.pipe process.stdout
// Output: 
// 2,3,4,1 
// b,c,d,a 

You may run this script with the command node samples/async.js. The call parallel(1) will restrict the number of parallel callback to 1, thus enabling sequential mode. Also, note how the use callback is requesting two arguments, the data to mutate and the callback to call when ready.

var mutate = require('mutate');
mutate()
.parallel(1)
.use(function(rowcallback){
  setImmediate(function(){
    row.unshift(row.pop());
    callback(row);
  }
})
.write( ['1','2','3','4'] )
.write( ['a','b','c','d'] )
.pipe process.stdout
// Output: 
// 2,3,4,1 
// b,c,d,a 

Tests are executed with mocha. To install it, simple run npm install, it will install mocha and its dependencies in your project "node_modules" directory.

To run the tests:

npm test

To generate the JavaScript files:

make build

The test suite is run online with Travis against Node.js version 0.6, 0.7, 0.8 and 0.9.

  • David Worms: <https://github.com/wdavidw>