# promise-hash

> Adds an RSVP-like Promise.hash() method for resolving groups of promises.

Latest version **1.3.0** (published 2019-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-hash
pnpm add promise-hash
yarn add promise-hash
bun add promise-hash
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-08-19 |
| First published | 2016-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/promise-hash) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Mike Timofiiv |
| Maintainers | mtimofiiv |
| Keywords | promise, nodejs, hash, promises |

## Links

- npm: https://www.npmjs.com/package/promise-hash
- Repository: https://github.com/mtimofiiv/promise-hash
- Homepage: https://github.com/mtimofiiv/promise-hash#readme
- Issues: https://github.com/mtimofiiv/promise-hash/issues
- npm.io page: https://npm.io/package/promise-hash

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2019-08-19
- 1.2.0 — 2017-07-18
- 1.1.0 — 2017-07-10
- 1.0.0 — 2016-08-15
- 0.9.0 — 2016-08-03
- 0.0.0 — 2016-08-03

## README

# promise-hash [![npm](https://img.shields.io/npm/dm/promise-hash.svg)](https://www.npmjs.com/package/promise-hash) [![Travis](https://img.shields.io/travis/mtimofiiv/promise-hash.svg?maxAge=2592000)](https://travis-ci.org/mtimofiiv/promise-hash)

In the current [Promises](https://www.promisejs.org/) implementation that Node.js uses, there exists the `Promise.all()` method, which resolves an array of promises. But what that implementation really misses is the way the [rsvp](https://github.com/tildeio/rsvp.js/) library allows you to pass an object to a promise and retain the data structure of that promise.

This library adds this functionality.

## Getting Started

```
npm install --save promise-hash
```

In your app, you can then do this:

```js
require('promise-hash');
```

Because it functions as a _polyfill_, all you need to do is include this in your code and the `Promise` object will be polyfilled to include the `#hash()` method.

If you prefer to not to polyfill the `Promise` object, you can use it directly:

```js
var hash = require('promise-hash/lib/promise-hash')

```

## Usage Example

```js
require('promise-hash');

function dummyPromise(value) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, 100, value);
  });
}

const promises = {
  promise1: dummyPromise('this is the first promise'),
  promise2: dummyPromise('this is the second promise'),
  promise3: dummyPromise('this is the third promise')
};

Promise.hash(promises).then(results => {
  console.log(results); // { promise1: 'this is the first promise', promise2: ... }
});
```

## Nodejs Garbage Collection

If you start getting `Promise.hash is not a function`, then the culprit is Nodejs's garbage collection. I'm looking into ways of solving this properly (feel free to send me a note if you know a good way!), but in the meantime, try putting the `require` into an active closure.

---
_Source: https://npm.io/package/promise-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
