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: about 1 month 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 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-08T04:42:25.000Z (about 5 years ago)
- Last Synced: 2025-12-26T10:00:45.487Z (5 months ago)
- Topics: p-iteration, p-map, pmap, promises
- Language: TypeScript
- Homepage:
- Size: 213 KB
- Stars: 1
- Watchers: 1
- 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)