Gathering detailed insights and metrics for p-map
Gathering detailed insights and metrics for p-map
Gathering detailed insights and metrics for p-map
Gathering detailed insights and metrics for p-map
p-map-series
Map over promises serially
p-iteration
Make array iteration easy when using async/await and Promises
p-map-values
A function similar to lodash.mapValues or Ramda.mapObjIndexed, but for async functions
@esm2cjs/p-map
Map over promises concurrently. This is a fork of sindresorhus/p-map, but with CommonJS support.
npm install p-map
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
99.5
Quality
76.8
Maintenance
100
Vulnerability
100
License
JavaScript (91.35%)
TypeScript (8.65%)
Total Downloads
9,884,917,515
Last Day
9,854,969
Last Week
52,349,747
Last Month
211,224,935
Last Year
2,201,057,624
MIT License
1,422 Stars
65 Commits
62 Forks
14 Watchers
1 Branches
17 Contributors
Updated on May 09, 2025
Minified
Minified + Gzipped
Latest Version
7.0.3
Package Id
p-map@7.0.3
Unpacked Size
20.69 kB
Size
5.66 kB
File Count
5
NPM Version
10.9.0
Node Version
23.3.0
Published on
Dec 05, 2024
Cumulative downloads
Total Downloads
Last Day
1.8%
9,854,969
Compared to previous day
Last Week
13.1%
52,349,747
Compared to previous week
Last Month
2.4%
211,224,935
Compared to previous month
Last Year
8.4%
2,201,057,624
Compared to previous year
Map over promises concurrently
Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
This is different from Promise.all()
in that you can control the concurrency and also decide whether or not to stop iterating when there's an error.
1npm install p-map
1import pMap from 'p-map'; 2import got from 'got'; 3 4const sites = [ 5 getWebsiteFromUsername('sindresorhus'), //=> Promise 6 'https://avajs.dev', 7 'https://github.com' 8]; 9 10const mapper = async site => { 11 const {requestUrl} = await got.head(site); 12 return requestUrl; 13}; 14 15const result = await pMap(sites, mapper, {concurrency: 2}); 16 17console.log(result); 18//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
Returns a Promise
that is fulfilled when all promises in input
and ones returned from mapper
are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array
of the fulfilled values returned from mapper
in input
order.
Returns an async iterable that streams each return value from mapper
in order.
1import {pMapIterable} from 'p-map'; 2 3// Multiple posts are fetched concurrently, with limited concurrency and backpressure 4for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) { 5 console.log(post); 6};
Type: AsyncIterable<Promise<unknown> | unknown> | Iterable<Promise<unknown> | unknown>
Synchronous or asynchronous iterable that is iterated over concurrently, calling the mapper
function for each element. Each iterated item is await
'd before the mapper
is invoked so the iterable may return a Promise
that resolves to an item.
Asynchronous iterables (different from synchronous iterables that return Promise
that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
Type: Function
Expected to return a Promise
or value.
Type: object
Type: number
(Integer)
Default: Infinity
Minimum: 1
Number of concurrently pending promises returned by mapper
.
Only for pMapIterable
Type: number
(Integer)
Default: options.concurrency
Minimum: options.concurrency
Maximum number of promises returned by mapper
that have resolved but not yet collected by the consumer of the async iterable. Calls to mapper
will be limited so that there is never too much backpressure.
Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
Only for pMap
Type: boolean
Default: true
When true
, the first mapper rejection will be rejected back to the consumer.
When false
, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an AggregateError
containing all the errors from the rejected promises.
Caveat: When true
, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, all mappers are invoked on startup and will continue after the first rejection. Issue #51 can be implemented for abort control.
Only for pMap
Type: AbortSignal
You can abort the promises using AbortController
.
1import pMap from 'p-map'; 2import delay from 'delay'; 3 4const abortController = new AbortController(); 5 6setTimeout(() => { 7 abortController.abort(); 8}, 500); 9 10const mapper = async value => value; 11 12await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal}); 13// Throws AbortError (DOMException) after 500 ms.
Return this value from a mapper
function to skip including the value in the returned array.
1import pMap, {pMapSkip} from 'p-map'; 2import got from 'got'; 3 4const sites = [ 5 getWebsiteFromUsername('sindresorhus'), //=> Promise 6 'https://avajs.dev', 7 'https://example.invalid', 8 'https://github.com' 9]; 10 11const mapper = async site => { 12 try { 13 const {requestUrl} = await got.head(site); 14 return requestUrl; 15 } catch { 16 return pMapSkip; 17 } 18}; 19 20const result = await pMap(sites, mapper, {concurrency: 2}); 21 22console.log(result); 23//=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
Promise.all()
but for Map
and Object
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More