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

through2-filter

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

through2-filter

A through2 to create an Array.prototype.filter analog for streams.

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
756K
decreased by-33.91%
Maintainers
1
Weekly downloads
 
Created

What is through2-filter?

The through2-filter npm package is a thin wrapper around node's transform streams designed to create filtering streams using a simple function. It is built on top of through2 and allows users to easily filter chunks of data in a stream based on a condition specified in a function.

What are through2-filter's main functionalities?

Synchronous Filtering

This feature allows for synchronous filtering of stream data. The provided code creates a filter stream that only passes through chunks of data that are longer than 10 characters.

const through2Filter = require('through2-filter');
const filterStream = through2Filter(chunk => chunk.length > 10);
process.stdin.pipe(filterStream).pipe(process.stdout);

Asynchronous Filtering

This feature supports asynchronous filtering. The example demonstrates filtering objects based on the 'age' property, allowing only those with an age greater than 20 to pass through, using an asynchronous test with a timeout.

const through2Filter = require('through2-filter').obj;
const filterStream = through2Filter((chunk, enc, callback) => {
  setTimeout(() => {
    callback(null, chunk.age > 20);
  }, 100);
});
process.stdin.pipe(filterStream).pipe(process.stdout);

Other packages similar to through2-filter

Keywords

FAQs

Package last updated on 20 Apr 2024

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