1.1.2 • Published 3 years ago

p-map-lite v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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 :tada:
  • 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.

ParameterTypeDescription
inputArrayRequired. Array to be iterated over in the mapper function.
mapperFunction/CallbackRequired. An callback function to handle the logic just like in the built-in map method.

License

MIT

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago