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

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.

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
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 10 Jun 2014

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