https://github.com/rocktimsaikia/p-map-lite
A lightweight p-map version for daily promise uses.
https://github.com/rocktimsaikia/p-map-lite
p-iteration p-map pmap promises
Last synced: 2 months ago
JSON representation
A lightweight p-map version for daily promise uses.
- Host: GitHub
- URL: https://github.com/rocktimsaikia/p-map-lite
- Owner: rocktimsaikia
- License: mit
- Created: 2021-04-24T04:46:53.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-08T04:42:25.000Z (about 4 years ago)
- Last Synced: 2025-03-18T10:59:45.730Z (2 months ago)
- Topics: p-iteration, p-map, pmap, promises
- Language: TypeScript
- Homepage:
- Size: 213 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# p-map-lite
 
A lightweight p-map version for daily promise uses.
### Features
- Lightweight (`~180 bytes`) - zero dependencies :tada:
- Simple and easy to use for daily promise uses
- Portable - both `esm` and `cjs` support
### Usage
```bash
npm install p-map-lite
``````javascript
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,...}]
})();
```
### API
#### pMap(input, mapper)
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. |
### License
[MIT](./LICENSE) License © 2021 [Rocktim Saikia](https://github.com/rocktimsaikia)