Skip to content

Latest commit

 

History

History
59 lines (36 loc) · 1.6 KB

README.md

File metadata and controls

59 lines (36 loc) · 1.6 KB

p-map-lite

GitHub Workflow Status (branch) npm

A lightweight p-map version for daily promise uses.


Features

  • Lightweight (~180 bytes) - zero dependencies 🎉
  • Simple and easy to use for daily promise uses
  • Portable - both esm and cjs support

Usage

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,...}]
})();

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 © 2021 Rocktim Saikia