Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unique-stream

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unique-stream

node.js through stream that emits a unique stream of objects based on criteria

  • 2.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7M
decreased by-12.96%
Maintainers
3
Weekly downloads
 
Created

What is unique-stream?

The unique-stream npm package is used to filter out duplicate objects in a stream based on a specified property or a custom function. It ensures that only unique items pass through the stream, which can be particularly useful when dealing with large datasets or streams of data where duplicates need to be removed.

What are unique-stream's main functionalities?

Filter unique objects by property

This feature allows you to filter out duplicate objects in a stream based on a specified property. In this example, objects with the same 'id' property will be considered duplicates, and only unique objects will be passed through the stream.

const unique = require('unique-stream');
const through = require('through2');

const stream = through.obj();

stream.pipe(unique('id')).pipe(through.obj((data, enc, callback) => {
  console.log(data);
  callback();
}));

stream.write({ id: 1, name: 'Alice' });
stream.write({ id: 2, name: 'Bob' });
stream.write({ id: 1, name: 'Alice' });
stream.end();

Filter unique objects by custom function

This feature allows you to filter out duplicate objects in a stream based on a custom function. In this example, objects with the same 'name' property will be considered duplicates, and only unique objects will be passed through the stream.

const unique = require('unique-stream');
const through = require('through2');

const stream = through.obj();

stream.pipe(unique((data) => data.name)).pipe(through.obj((data, enc, callback) => {
  console.log(data);
  callback();
}));

stream.write({ id: 1, name: 'Alice' });
stream.write({ id: 2, name: 'Bob' });
stream.write({ id: 3, name: 'Alice' });
stream.end();

Other packages similar to unique-stream

Keywords

FAQs

Package last updated on 18 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc