Gathering detailed insights and metrics for p-iteration
Gathering detailed insights and metrics for p-iteration
Gathering detailed insights and metrics for p-iteration
Gathering detailed insights and metrics for p-iteration
p
pattern matching in javascript for asyncronous iteration
p-iteration-with-concurrency
Make array iteration easy when using async/await and Promises
@taktikorg/unde-animi-omnis
<p align="center"> <a href="https://www.npmjs.com/package/@taktikorg/unde-animi-omnis"><img src="https://img.shields.io/npm/v/@taktikorg/unde-animi-omnis"></a> <a href=""><img src="https://img.shields.io/github/actions/workflow/status/RemiMyrset/@taktikor
@teamteanpm2024/quam-dolores-impedit
<p align="center"> <img src="https://github.com/teamteanpm2024/quam-dolores-impedit/blob/main/@teamteanpm2024/quam-dolores-impedit.svg" width="400px" alt="Arehs Logo" /> <p>
Utilities that make array iteration easy when using async/await or Promises
npm install p-iteration
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
92,878,184
Last Day
94,021
Last Week
477,817
Last Month
2,047,792
Last Year
25,477,680
352 Stars
79 Commits
19 Forks
9 Watchers
4 Branches
4 Contributors
Updated on Aug 15, 2024
Minified
Minified + Gzipped
Latest Version
1.1.8
Package Id
p-iteration@1.1.8
Size
5.22 kB
NPM Version
6.7.0
Node Version
11.11.0
Published on
Mar 15, 2019
Cumulative downloads
Total Downloads
Last Day
8.3%
94,021
Compared to previous day
Last Week
2.8%
477,817
Compared to previous week
Last Month
0.1%
2,047,792
Compared to previous month
Last Year
-14.4%
25,477,680
Compared to previous year
6
Make array iteration easy when using async/await and promises
Promise
, making them awaitable and thenable$ npm install --save p-iteration
Smooth asynchronous iteration using async/await
:
1const { map } = require('p-iteration'); 2 3// map passing an async function as callback 4function getUsers (userIds) { 5 return map(userIds, async userId => { 6 const response = await fetch(`/api/users/${userId}`); 7 return response.json(); 8 }); 9} 10 11// map passing a non-async function as callback 12async function getRawResponses (userIds) { 13 const responses = await map(userIds, userId => fetch(`/api/users/${userId}`)); 14 // ... do some stuff 15 return responses; 16} 17 18// ...
1const { filter } = require('p-iteration'); 2 3async function getFilteredUsers (userIds, name) { 4 const filteredUsers = await filter(userIds, async userId => { 5 const response = await fetch(`/api/users/${userId}`); 6 const user = await response.json(); 7 return user.name === name; 8 }); 9 // ... do some stuff 10 return filteredUsers; 11} 12 13// ...
All methods return a Promise so they can just be used outside an async function just with plain Promises:
1const { map } = require('p-iteration'); 2 3map([123, 125, 156], (userId) => fetch(`/api/users/${userId}`)) 4 .then((result) => { 5 // ... 6 }) 7 .catch((error) => { 8 // ... 9 });
If there is a Promise in the array, it will be unwrapped before calling the callback:
1const { forEach } = require('p-iteration'); 2const fetchJSON = require('nonexistent-module'); 3 4function logUsers () { 5 const users = [ 6 fetchJSON('/api/users/125'), // returns a Promise 7 { userId: 123, name: 'Jolyne', age: 19 }, 8 { userId: 156, name: 'Caesar', age: 20 } 9 ]; 10 return forEach(users, (user) => { 11 console.log(user); 12 }); 13}
1const { find } = require('p-iteration'); 2const fetchJSON = require('nonexistent-module'); 3 4function findUser (name) { 5 const users = [ 6 fetchJSON('/api/users/125'), // returns a Promise 7 { userId: 123, name: 'Jolyne', age: 19 }, 8 { userId: 156, name: 'Caesar', age: 20 } 9 ]; 10 return find(users, (user) => user.name === name); 11}
The callback will be invoked as soon as the Promise is unwrapped:
1const { forEach } = require('p-iteration'); 2 3// function that returns a Promise resolved after 'ms' passed 4const delay = (ms) => new Promise(resolve => setTimeout(() => resolve(ms), ms)); 5 6// 100, 200, 300 and 500 will be logged in this order 7async function logNumbers () { 8 const numbers = [ 9 delay(500), 10 delay(200), 11 delay(300), 12 100 13 ]; 14 await forEach(numbers, (number) => { 15 console.log(number); 16 }); 17}
The methods are implementations of the ES5 Array iteration methods we all know with the same syntax, but all return a Promise
. Also, with the exception of reduce()
, all methods callbacks are run concurrently. There is a series version of each method, called: ${methodName}Series
, series methods use the same API that their respective concurrent ones.
There is a link to the original reference of each method in the docs of this module:
Extending native objects is discouraged and I don't recommend it, but in case you know what you are doing, you can extend Array.prototype
to use the above methods as instance methods. They have been renamed as async${MethodName}
, so the original ones are not overwritten.
1const { instanceMethods } = require('p-iteration'); 2 3Object.assign(Array.prototype, instanceMethods); 4 5async function example () { 6 const foo = await [1, 2, 3].asyncMap((id) => fetch(`/api/example/${id}`)); 7}
MIT © Antonio V
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 4/24 approved changesets -- score normalized to 1
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
security policy file not detected
Details
Reason
license file not detected
Details
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
Reason
48 existing vulnerabilities detected
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