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-all-properties

v4.0.4

Published

A helper function that recevies an object with a promise in each property and returns a promise that resolves to an object with the same properties and the resolved values of the promises

Downloads

7,809

Readme

Promise all properties

tests

A helper function that receives an object with a Promise in each property and returns a promise that resolves to an object with the same properties and the resolved values of the promises.

The returned promise is rejected in the following cases:

  1. The input argument is not an "object"
  2. At least one of the promises are rejected

Requirements

  • ES6 Promise supporting Javascript engine (browser or Node.js), or at least an ES6 Promise polyfill
  • a node package manager installed (such as NPM or Yarn)

Usage example (ES6/Typescript):

import promiseAllProperties from 'promise-all-properties';

const promisesObject = {
  someProperty: Promise.resolve('resolve value'),
  anotherProperty: Promise.resolve('another resolved value'),
};

const promise = promiseAllProperties(promisesObject);

promise.then((resolvedObject) => {
  console.log(resolvedObject);
  // {
  //   someProperty: 'resolve value',
  //   anotherProperty: 'another resolved value'
  // }
});

Promise all settled properties

This helper function works the same as promiseAllProperties, except it uses Promise.allSettled instead of Promise.all. It is therefore possible to get the status of all the promises, regardless of how many of them were fulfilled or rejected.

Usage example:

import {promiseAllSettledProperties} from 'promise-all-properties';

const promisesObject = {
  someProperty: Promise.resolve('resolve value'),
  anotherProperty: Promise.reject(new Error('a rejection')),
  yetAnotherProperty: Promise.reject(new Error('another rejection')),
};

const promise = promiseAllSettledProperties(promisesObject);

promise.then((resolvedObject) => {
  console.log(resolvedObject);
  // {
  //   someProperty: {status: 'fulfilled', value: 'resolve value'},
  //   anotherProperty: {status: 'rejected', reason: Error('a rejection')},
  //   yetAnotherProperty: {status: 'rejected', reason: Error('another rejection')}
  // }
});

// By comparison, promiseAllProperties(promisesObject) would reject with Error('a rejection')

Breaking changes

v4.0.0

  • Minimum Node.js version is now 12.20.0 to support the promiseAllSettledProperties method

v3.0.0

  • Passing an Array of values causes the promise to be rejected as invalid
  • Stricter TypeScript signature now errors on non-object arguments.

Developers

Run tests:

npm test

Build:

npm run build

Contributions:

PR's are welcome just make sure the the PR is squashed (one commit) and the commit messages starts with one of the following prefixes:

[INITIAL]: The initial commit
[FEAT]: Only changes that creating new features or modofying existing features, that are not bug fixes
[FIX]: Only bug fixes
[DOCS]: Only Documentation changes
[STYLE]: Only changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
[REFACTOR]: Only code changes that are neither fixes or features
[TEST]: Only changes that are adding new tests or modifying existing tests
[TOOLS]: Only changes that affect external processeses like build tools, dev tools, auxiliary tools and libraries such as documentation generation
[CLEANUP]: Only code removal: code lines, comment lines or files without affecting the project whatsoever

License

Public domain Unlicense