3 node.js through stream that emits a unique stream of objects based on criteria
5 [![build status](https://secure.travis-ci.org/eugeneware/unique-stream.png)](http://travis-ci.org/eugeneware/unique-stream)
12 $ npm install unique-stream
17 ### Dedupe a ReadStream based on JSON.stringify:
20 var unique = require('unique-stream')
21 , Stream = require('stream');
23 // return a stream of 3 identical objects
24 function makeStreamOfObjects() {
28 for (var i = 0; i < 3; i++) {
29 setImmediate(function () {
30 s.emit('data', { name: 'Bob', number: 123 });
42 // Will only print out one object as the rest are dupes. (Uses JSON.stringify)
45 .on('data', console.log);
49 ### Dedupe a ReadStream based on an object property:
52 // Use name as the key field to dedupe on. Will only print one object
55 .on('data', console.log);
58 ### Dedupe a ReadStream based on a custom function:
61 // Use a custom function to dedupe on. Use the 'number' field. Will only print one object.
63 .pipe(function (data) {
66 .on('data', console.log);
69 ## Dedupe multiple streams
71 The reason I wrote this was to dedupe multiple object streams:
74 var aggregator = unique();
88 aggregator.on('data', console.log);