p-map-series
Advanced tools
Comparing version 1.0.0 to 2.0.0
20
index.js
'use strict'; | ||
const pReduce = require('p-reduce'); | ||
module.exports = (iterable, iterator) => { | ||
const ret = []; | ||
const pMapSeries = async (iterable, mapper) => { | ||
const result = []; | ||
let index = 0; | ||
return pReduce(iterable, (a, b, i) => { | ||
return Promise.resolve(iterator(b, i)).then(val => { | ||
ret.push(val); | ||
}); | ||
}).then(() => ret); | ||
for (const value of iterable) { | ||
// eslint-disable-next-line no-await-in-loop | ||
result.push(await mapper(await value, index++)); | ||
} | ||
return result; | ||
}; | ||
module.exports = pMapSeries; | ||
module.exports.default = pMapSeries; |
{ | ||
"name": "p-map-series", | ||
"version": "1.0.0", | ||
"description": "Map over promises serially", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-map-series", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"map", | ||
"collection", | ||
"iterable", | ||
"iterator", | ||
"fulfilled", | ||
"serial", | ||
"serially", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"dependencies": { | ||
"p-reduce": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"delay": "^1.3.1", | ||
"time-span": "^1.0.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "p-map-series", | ||
"version": "2.0.0", | ||
"description": "Map over promises serially", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-map-series", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"map", | ||
"collection", | ||
"iterable", | ||
"iterator", | ||
"fulfilled", | ||
"serial", | ||
"serially", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"delay": "^4.1.0", | ||
"time-span": "^3.0.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # p-map-series [![Build Status](https://travis-ci.org/sindresorhus/p-map-series.svg?branch=master)](https://travis-ci.org/sindresorhus/p-map-series) | ||
``` | ||
$ npm install --save p-map-series | ||
$ npm install p-map-series | ||
``` | ||
@@ -29,3 +29,4 @@ | ||
const mapper = keyword => fetchScore(keyword).then(score => { | ||
const mapper = async keyword => { | ||
const score = await fetchScore(keyword); | ||
scores.push(score); | ||
@@ -35,17 +36,21 @@ return {keyword, score}; | ||
pMapSeries(keywords, mapper).then(result => { | ||
console.log(result); | ||
(async () => { | ||
console.log(await pMapSeries(keywords, mapper)); | ||
/* | ||
[{ | ||
keyword: 'unicorn', | ||
score: 99 | ||
}, { | ||
keyword: 'rainbow', | ||
score: 70 | ||
}, { | ||
keyword: 'pony', | ||
score: 79} | ||
[ | ||
{ | ||
keyword: 'unicorn', | ||
score: 99 | ||
}, | ||
{ | ||
keyword: 'rainbow', | ||
score: 70 | ||
}, | ||
{ | ||
keyword: 'pony', | ||
score: 79 | ||
} | ||
] | ||
*/ | ||
}); | ||
})(); | ||
``` | ||
@@ -62,3 +67,3 @@ | ||
Type: `Iterable<Promise|any>` | ||
Type: `Iterable<Promise | unknown>` | ||
@@ -65,0 +70,0 @@ Mapped over serially in the `mapper` function. |
Sorry, the diff of this file is not supported yet
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4584
0
5
25
86
0
5
- Removedp-reduce@^1.0.0
- Removedp-reduce@1.0.0(transitive)