promise_mtd
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -9,2 +9,4 @@ 'use strict'; | ||
promise_mtd.filter = require('./promise_mtd/filter.js'); | ||
promise_mtd.transform = require('./promise_mtd/transform.js'); | ||
@@ -11,0 +13,0 @@ |
{ | ||
"name": "promise_mtd", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Set of methods allowing simplify work with Promises in cycle. Methods: forEach, map, while, transform, parallel", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# promise_mtd | ||
Set of methods allowing to simplify work with promises in cycle. | ||
* Implementation of ```forEach``` and ```map``` for working with array data when it's needed to apply asynchronous function to each element. | ||
* Implementation of ```forEach```, ```map```, ```filter``` for working with array data when it's needed to apply asynchronous function to each element. | ||
* Method ```transform``` allows to iterate asynchronously over an array similarly to ```map```, but also it can skip unnecessary data. | ||
@@ -53,2 +53,19 @@ * Implementation of cycle ```while``` for using with promise. | ||
### filter(Array<any>, Function(el, index): Promise<Boolean>) | ||
```Filter``` | ||
```js | ||
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 ] | ||
}(); | ||
``` | ||
### parallel(Array<any>, Function(el, index)) | ||
@@ -136,7 +153,7 @@ Equivalent of ```Promise.all``` but with limit | ||
// { t1: 2000, t2: 1000 } | ||
console.log(await promise_mtd.all({ t1, t2 })); | ||
console.log(await promiseMtd.all({ t1, t2 })); | ||
// as Promise.all | ||
// [ 2000, 1000 ] | ||
console.log(await promise_mtd.all([ t1, t2 ])); | ||
console.log(await promiseMtd.all([ t1, t2 ])); | ||
} catch (err) { | ||
@@ -143,0 +160,0 @@ console.log('Raise', err); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12731
11
270
161