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

promised-array

v1.1.2

Published

Array combined with Promise, chainable, asynchronous methods and callbacks ready for async/await.

Downloads

5

Readme

PromisedArray

NPM version Build Status Coverage Status Codacy Badge devDependency Status JavaScript Style Guide

NPM Downloads

PromisedArray combines the interface of Promise and Array.

  • It is a native Promise. You can use it in a promise chain and with the await operator.
  • It includes all members of Array.prototype. They will apply to the array, which the promise resolves to and they return a promise to the result of the original method.
  • Methods of Array.prototype, which expect callbacks, accept also asynchronous callbacks. They will wait, until the callback's promise resolves and continue with the result.
  • No need to mark the callback by the async keyword, if they don't use teh await keyword and just return a promise.
  • Callback execution possible either sequentially or concurrently.
  • No dependencies on other modules.

Warnig: still in the development.

Table of Contents

Synopsis

// Print an array of names of items with the specified keys.
new PromisedArray([1, 2, 3])
  .map(key => fetch('https://server.com/items/' + key))
  .map(response => response.json().name)
  .then(names => console.log(names))
  .catch(error => console.error(error))

Description

PromisedArray is a function object with the prototype combined from Promise and Array. Instances can be constructed either from an array or from a promise resolving to an array.

// Print names of all items.
const promise = fetch('https://server.com/items')
  .then(response => response.json())
PromisedArray
  .fromPromise(promise)
  .forEach({ name } => console.log(name))
  .catch(console.error)

Methods of the PromisedArray prototype, which share their names with their corresponding methods of the original Array prototype, have the same semantics and guarantees the same order of processing array items. They return the same result, only wrapped in a PromisedArray instance, if it is an array, or in a stqndqrd promise in other cases. Methods, which accept callbacks as parameters, check, if the result of the callback is a promise or not. If it is, they wait for its resolution and continue with the result. If the promise gets rejected, the whole result promise will be rejected and the loop over array items aborted.

Methods which end with Concurrently execute callbacks for every array item concurrently and wait for resulution of all promises for callback call results, before they process the results. The order callback execution may differ from the original method from the Array prototype. If the method returns an array, order of results in that array is guaranteed to be the same as the original method from the Array prototype would return.

License

Copyright (c) 2019 Ferdinand Prantl

Licensed under the MIT license.