npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

transform-clump

1.0.5 • Public • Published

transform-clump

Build Status Coverage Status NPM version

A transform stream that clumps data into an array of a specified size. The oldest items in the array are replaced by the newer items as they stream in.

Installation

$ npm install transform-clump --save

Example

var stream = require('stream');
var clump = require('transform-clump');
var source = stream.PassThrough({ objectMode: true });
var dest = stream.PassThrough({ objectMode: true });
var result;
 
source.pipe(clump(5)).pipe(dest);
 
dest.on('data', function(chunk){
  result = chunk;
});
dest.on('end', function(){
  // => [ { foo: 5 }, { foo: 1 }, { foo: 2 }, { foo: 3 }, { foo: 4 } ]
  console.log(result);
});
 
for (var i = 0, j = 5; i < j; i++) source.push({ foo: i });
source.end({ foo: i });

API

var clump = transformClump(size)

Initialise a new TransformClump with the given size.

Testing

$ make test

To generate a coverage report:

$ make test-cov

Credits

  • urlgrey for the Makefile inspiration.

install

npm i transform-clump

Downloadsweekly downloads

8

version

1.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability