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

it-map

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-map

Maps the values yielded by an async iterator

  • 3.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is it-map?

The it-map npm package is a utility for transforming async iterables. It allows you to apply a mapping function to each item in an async iterable, similar to how Array.prototype.map works for arrays.

What are it-map's main functionalities?

Basic Mapping

This feature allows you to apply a simple mapping function to each item in an async iterable. In this example, each number yielded by the async generator is doubled.

const itMap = require('it-map');

async function* asyncGenerator() {
  yield 1;
  yield 2;
  yield 3;
}

const mapped = itMap(asyncGenerator(), x => x * 2);

(async () => {
  for await (const value of mapped) {
    console.log(value); // 2, 4, 6
  }
})();

Async Mapping Function

This feature allows you to use an async function as the mapping function. In this example, each number is doubled after a 100ms delay.

const itMap = require('it-map');

async function* asyncGenerator() {
  yield 1;
  yield 2;
  yield 3;
}

const mapped = itMap(asyncGenerator(), async x => {
  await new Promise(resolve => setTimeout(resolve, 100));
  return x * 2;
});

(async () => {
  for await (const value of mapped) {
    console.log(value); // 2, 4, 6
  }
})();

Other packages similar to it-map

FAQs

Package last updated on 26 May 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