p-map-lite
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

p-map-lite

A lightweight (~180 bytes) p-map version for daily promise uses.

GitHub Workflow Status (branch) npm

An opinionated lightweight promise map module. Similar to packages like p-iteration, p-map.
Except it removes all the unused options and aims to be as simple as possible.

Highlights

  • Lightweight (~180 bytes). Zero dependencies 🎉
  • Simple and easy to use for daily promise uses.
  • Portable. Both esm and cjs support.

Setup

Install the package:

npm install p-map-lite

Usage

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

Readme

Keywords

none

Package Sidebar

Install

npm i p-map-lite

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

196 kB

Total Files

12

Last publish

Collaborators

  • rocktimsaikia