npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

promise-array

v1.2.5

Published

#### ✅ All 12 tests pass

Downloads

4

Readme

Promise Array 1.2.4

License: MIT

✅ All 12 tests pass

Table of Contents

Overview

Content

Description

A small library providing asynchronous array methods for promises.

Installation

Browser

Just download the PromiseArray.min.js and include it in an HTML <script> tag

eg:

<script src="PromiseArray.min.js"></script>

Node

npm i -S promise-array

Notes

This differs from Promise.all in that it does not wait for all the promises to resolve. As each promise resolves, it executes each method on that value.

For example, you want to update a list of values and you don't want the interface to appear frozen.

Example

var statusLine = document.querySelector('#status-line');

PromiseArray(listOfPromises)
  .map(a => a * 2)
  .filter(a => a < 100)
  .forEach(
    function (value) {
      var el = document.createElement('div');
      el.innerHtml = value;
      document.body.append(el);
    }
  )
  .then(
    function () {
      statusLine.innerHtml = 'Complete';
    }
  )
  .catch(
    function () {
      statusLine.innerHtml = 'Incomplete, please try again.';
    }
  )

catch ... (top)

When an item in your list does not resolve, it will not trigger a catch callback. Instead, once all the items have been attempted, you will get 2 arguments passed to the then method.

The only error which will trigger the catch method is going to be if an invalid promise is passed to the constructor.

filter ... (top)

Works the same as the default .filter function, with the exception that it can also return a Promise

var myPromises = [promise1, promise2];
PromiseArray(myPromises)
  .filter(function (value, index) {
    return value > 100;
  });
PromiseArray(myPromises)
  .map(function (value) {
    return new Promise(...)
  });

forEach ... (top)

Works the same as the default .forEach function.

var myPromises = [promise1, promise2];
PromiseArray(myPromises)
  .forEach(function (value, index) {
    // My code
  });

map ... (top)

Works the same as the default .map function, with the exception that it can also return a Promise

var myPromises = [promise1, promise2];
PromiseArray(myPromises)
  .map(function (value, index) {
    return value.toLowerCase();
  });
PromiseArray(myPromises)
  .map(function (value) {
    return new Promise(...)
  });

then ... (top)

Returns two arguments:

  • An array of values
  • An array of error objects

Construction of the error array item:

{
  promise : [ Rejected Promise ],
  error : [ Error ],
  index : [ Item Index ]
}

Tests

   1. Promise.Array: map (undefined)..................................... ✅
   2. Promise.Array: map (NaN)........................................... ✅
   3. Promise.Array: forEach (should be)................................. ✅
   4. Promise.Array: forEach (not be).................................... ✅
   5. Promise.Array: filter (not be)..................................... ✅
   6. Promise.Array: filter (should be).................................. ✅
   7. Promise.Array: map & filter (should be)............................ ✅
   8. Promise.Array: map & filter (not be)............................... ✅
   9. Promise.Array: map, filter & forEach (should be)................... ✅
  10. Promise.Array: map, filter & forEach (should not be undefined)..... ✅
  11. Promise.Array: map to promise (with rejection)..................... ✅
  12. Promise.Array: Invalid list of promises............................ ✅