Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
promise_mtd
Advanced tools
Set of methods allowing simplify work with Promises in cycle. Methods: forEach, map, while, transform, parallel
Set of methods allowing to simplify work with promises in cycle.
forEach
, map
, filter
for working with array data when it's needed to apply asynchronous function to each element.transform
allows to iterate asynchronously over an array similarly to map
, but also it can skip unnecessary data.asyncWhile
(while is reserved word) for using with promise.parallel
allows to run concurrently promises similarly to method Promise.all
, but with limit.all
allows to run concurrently promises similarly to method Promise.all
, but supports receipt of parameter such as object { k1: Promise, k2: Promise }
not only as array.The library has no dependencies 😀.
npm i promise_mtd -S
Foreach
over promises serially
const promiseMtd = require('promise_mtd');
void async function () {
await promiseMtd.forEach([ 300, 200, 100], async function (el, i) {
return new Promise((resolve, reject) => {
setTimeout(function() {
console.log(el);
resolve();
}, el+i);
});
});
}();
Map
over promises serially
const promiseMtd = require('promise_mtd');
void async function () {
let res = await promiseMtd.map([ 300, 200, 100], async function (el, i) {
return new Promise((resolve, reject) => {
setTimeout(function() {
resolve(el*2);
}, el*2);
});
});
console.log(res); // [ 600, 400, 200 ]
}();
Filter
const promiseMtd = require('promise_mtd');
void async function () {
let res = await promiseMtd.filter([ 0, 1, 2, 3 ], function(time, i) {
return new Promise((resolve, reject) => {
setTimeout(function() {
resolve(Boolean(i));
}, time * 1000);
});
});
console.log(res); // [ 1, 2, 3 ]
}();
Equivalent of Promise.all
but with limit
const promiseMtd = require('promise_mtd');
void async function() {
await promiseMtd.parallel([ 3000, 3000, 3000, 2000, 2000, 2000, 1000], 3, async function(el, i) {
return new Promise((resolve) => {
setTimeout(() => {
console.log(el);
resolve();
}, t);
});
});
}();
Iterating over an array and filter over promises
const promiseMtd = require('promise_mtd');
void async function() {
let res = await promiseMtd.transform([ 1, 2, 3, 4 ], function (el, i) {
if (el <= 2) {
return new Promise((resolve) => {
setTimeout(() => resolve({ el, i }), 1000);
});
}
});
console.log(res); // [ { el: 1, i: 0 }, { el: 2, i: 1 } ]
}();
While
over promises serially
const promiseMtd = require('promise_mtd');
void async function() {
let i = 0;
await promiseMtd.asyncWhile(() => i < 5, async function () {
console.log(i);
i++;
});
console.log(i); // 5
}();
All
over promises serially
const promiseMtd = require('promise_mtd');
void async function() {
var t1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(2000);
}, 2000);
});
var t2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1000);
}, 1000);
});
// { t1: 2000, t2: 1000 }
console.log(await promiseMtd.all({ t1, t2 }));
// as Promise.all
// [ 2000, 1000 ]
console.log(await promiseMtd.all([ t1, t2 ]));
}();
FAQs
Set of methods allowing simplify work with promises in cycle such as: forEach, map, find, filter, reduce, while, transform. Besides there are methods for comfortable work with promises or asynchronous operations - all, retry, timeout.
The npm package promise_mtd receives a total of 43 weekly downloads. As such, promise_mtd popularity was classified as not popular.
We found that promise_mtd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.