Filter stream of objects

npm install cop
60 downloads in the last month

cop - filter stream of objects

Build Status David DM

The cop Node.js module is a Transform stream (in object mode) which is configurable to emit specific properties of objects written to it. Furthermore, if provided with a filter function, cop can be used to massage data.


Property value by name

var cop = require('cop')
  , Readable = require('stream').Readable

var objs = [
  { thing: 'My hovercraft ' }
, { thing: 'is full ' }
, { thing: 'of eels.\n' }

var reader = new Readable({ objectMode:true })
  , length = objs.length
  , i = 0

reader._read = function () {
  reader.push(i < length ? objs[i++] : null)


Filter function

var cop = require('cop')
  , fstream = require('fstream')
  , reader = fstream.Reader({ path:process.cwd() })


function filter (obj) {
  return obj ? obj['path'] + '\n' : undefined


  • key Name of the property of which to emit the value

Provided a key, cop will emit the matching property of an object written to it. If the object has no matching property nothing is emitted.


  • filter Filter function which is applied to each object written to the stream

Alternatively a filter function can be provided, which is executed before data is emitted, hence, provides an opportunity to massage the data.




MIT License

npm loves you