Socket
Socket
Sign inDemoInstall

through2-map

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

through2-map

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


Version published
Weekly downloads
139K
increased by0.77%
Maintainers
1
Weekly downloads
 
Created

What is through2-map?

The through2-map package is a small utility for creating object streams that can be easily transformed. It is built on top of the through2 package and provides a simple API for mapping input chunks to output chunks, making it useful for data transformation tasks in a stream pipeline.

What are through2-map's main functionalities?

Basic Mapping

This feature allows you to transform each chunk of data passing through the stream. In this example, the input data is converted to uppercase.

const through2Map = require('through2-map');
const stream = through2Map(chunk => chunk.toString().toUpperCase());
process.stdin.pipe(stream).pipe(process.stdout);

Object Mode

This feature allows you to work with object streams. In this example, each object passing through the stream is augmented with a new property.

const through2Map = require('through2-map');
const stream = through2Map({ objectMode: true }, obj => ({ ...obj, transformed: true }));
stream.write({ key: 'value' });
stream.on('data', data => console.log(data));

Asynchronous Mapping

This feature allows you to perform asynchronous transformations on the data chunks. In this example, each chunk is converted to uppercase after a delay of 1 second.

const through2Map = require('through2-map');
const stream = through2Map({ wantStrings: true }, (chunk, done) => {
  setTimeout(() => done(null, chunk.toUpperCase()), 1000);
});
process.stdin.pipe(stream).pipe(process.stdout);

Other packages similar to through2-map

Keywords

FAQs

Package last updated on 13 Dec 2013

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