A lightweight p-map version for daily promise uses.
- Lightweight (
~180 bytes
) - zero dependencies 🎉 - Simple and easy to use for daily promise uses
- Portable - both
esm
andcjs
support
npm install p-map-lite
import pMap from 'p-map-lite';
const postIds = [1, 2, 3];
(async () => {
const output = await pMap(postIds, async () => {
const res = await fetch(`/api/posts/${id}`);
return res.json();
});
console.log(output);
//=> [{id: 1,...}, {id: 2,...}, {id: 3,...}]
})();
Returns a Promise
that is fulfilled when all of the input's promises have resolved, or if the input iterable contains no promises.
Parameter | Type | Description |
---|---|---|
input |
Array |
Required. Array to be iterated over in the mapper function. |
mapper |
Function/Callback |
Required. An callback function to handle the logic just like in the built-in map method. |
MIT License © 2021 Rocktim Saikia