p-map-series
Advanced tools
Comparing version 2.1.0 to 3.0.0
103
index.d.ts
@@ -1,66 +0,49 @@ | ||
declare const pMapSeries: { | ||
/** | ||
Map over promises serially. | ||
/** | ||
Map over promises serially. | ||
@param input - Mapped over serially in the `mapper` function. | ||
@param mapper - Expected to return a value. If it's a `Promise`, it's awaited before continuing with the next iteration. | ||
@returns Fulfills when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. | ||
@param input - Mapped over serially in the `mapper` function. | ||
@param mapper - Expected to return a value. If it's a `Promise`, it's awaited before continuing with the next iteration. | ||
@returns Fulfills when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. | ||
@example | ||
``` | ||
import pMapSeries = require('p-map-series'); | ||
@example | ||
``` | ||
import pMapSeries from 'p-map-series'; | ||
const keywords = [ | ||
getTopKeyword() //=> Promise | ||
'rainbow', | ||
'pony' | ||
]; | ||
const keywords = [ | ||
getTopKeyword() //=> Promise | ||
'rainbow', | ||
'pony' | ||
]; | ||
let scores = []; | ||
let scores = []; | ||
const mapper = async keyword => { | ||
const score = await fetchScore(keyword); | ||
scores.push(score); | ||
return {keyword, score}; | ||
}); | ||
const mapper = async keyword => { | ||
const score = await fetchScore(keyword); | ||
scores.push(score); | ||
return {keyword, score}; | ||
}); | ||
(async () => { | ||
console.log(await pMapSeries(keywords, mapper)); | ||
// [ | ||
// { | ||
// keyword: 'unicorn', | ||
// score: 99 | ||
// }, | ||
// { | ||
// keyword: 'rainbow', | ||
// score: 70 | ||
// }, | ||
// { | ||
// keyword: 'pony', | ||
// score: 79 | ||
// } | ||
// ] | ||
})(); | ||
``` | ||
*/ | ||
<ValueType, MappedValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
mapper: ( | ||
element: ValueType, | ||
index: number | ||
) => PromiseLike<MappedValueType> | MappedValueType | ||
): Promise<MappedValueType[]>; | ||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pMapSeries<ValueType, MappedValueType>( | ||
// input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
// mapper: ( | ||
// element: ValueType, | ||
// index: number | ||
// ) => PromiseLike<MappedValueType> | MappedValueType | ||
// ): Promise<MappedValueType[]>; | ||
// export = pMapSeries; | ||
default: typeof pMapSeries; | ||
}; | ||
export = pMapSeries; | ||
console.log(await pMapSeries(keywords, mapper)); | ||
// [ | ||
// { | ||
// keyword: 'unicorn', | ||
// score: 99 | ||
// }, | ||
// { | ||
// keyword: 'rainbow', | ||
// score: 70 | ||
// }, | ||
// { | ||
// keyword: 'pony', | ||
// score: 79 | ||
// } | ||
// ] | ||
``` | ||
*/ | ||
export default function pMapSeries<ValueType, MappedValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
mapper: ( | ||
element: ValueType, | ||
index: number | ||
) => PromiseLike<MappedValueType> | MappedValueType | ||
): Promise<MappedValueType[]>; |
10
index.js
@@ -1,4 +0,2 @@ | ||
'use strict'; | ||
const pMapSeries = async (iterable, mapper) => { | ||
export default async function pMapSeries(iterable, mapper) { | ||
const result = []; | ||
@@ -13,6 +11,2 @@ let index = 0; | ||
return result; | ||
}; | ||
module.exports = pMapSeries; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pMapSeries; | ||
} |
{ | ||
"name": "p-map-series", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Map over promises serially", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-map-series", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -37,8 +40,8 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"time-span": "^3.0.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"time-span": "^4.0.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# p-map-series [![Build Status](https://travis-ci.org/sindresorhus/p-map-series.svg?branch=master)](https://travis-ci.org/sindresorhus/p-map-series) | ||
# p-map-series | ||
@@ -7,3 +7,2 @@ > Map over promises serially | ||
## Install | ||
@@ -15,7 +14,6 @@ | ||
## Usage | ||
```js | ||
const pMapSeries = require('p-map-series'); | ||
import pMapSeries from 'p-map-series'; | ||
@@ -36,24 +34,21 @@ const keywords = [ | ||
(async () => { | ||
console.log(await pMapSeries(keywords, mapper)); | ||
/* | ||
[ | ||
{ | ||
keyword: 'unicorn', | ||
score: 99 | ||
}, | ||
{ | ||
keyword: 'rainbow', | ||
score: 70 | ||
}, | ||
{ | ||
keyword: 'pony', | ||
score: 79 | ||
} | ||
] | ||
*/ | ||
})(); | ||
console.log(await pMapSeries(keywords, mapper)); | ||
/* | ||
[ | ||
{ | ||
keyword: 'unicorn', | ||
score: 99 | ||
}, | ||
{ | ||
keyword: 'rainbow', | ||
score: 70 | ||
}, | ||
{ | ||
keyword: 'pony', | ||
score: 79 | ||
} | ||
] | ||
*/ | ||
``` | ||
## API | ||
@@ -77,3 +72,2 @@ | ||
## Related | ||
@@ -86,5 +80,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-p-map-series?utm_source=npm-p-map-series&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
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
87
Yes
5310
52