# promise-sos

> Helpers for using promise

Latest version **1.0.0** (published 2025-10-01) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2025-10-01 |
| First published | 2019-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 23.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Inaki Arroyo |
| Maintainers | inakiarroyo |
| Keywords | promise, promises, utils, helpers, typescript |

## Links

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2025-10-01
- 0.2.0 — 2019-01-11

## README

# Promise S.O.S

[![npm package](https://img.shields.io/npm/v/promise-sos/latest.svg)](https://www.npmjs.com/package/promise-sos)
[![npm downloads](https://img.shields.io/npm/dm/promise-sos.svg)](https://www.npmjs.com/package/promise-sos)
[![Types: TypeScript](https://img.shields.io/npm/types/promise-sos.svg)](https://www.typescriptlang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

> A lightweight, fully typed library providing utilities for working with JavaScript promises.

---

## ✨ Features

- 📦 **Tiny** and dependency-free
- 🔒 **Type-safe** – written in TypeScript
- ⚡ Works with **ESM** and **CommonJS**
- 🛠 Provides helpers for combining and managing promises

---

## 📥 Installation

```sh
npm install promise-sos
# or
yarn add promise-sos
```

---

## 🚀 Usage

### `promiseAllObject`

A helper function that extends `Promise.all` by allowing you to pass an **object of promises** (instead of an array).
It returns a promise that resolves to an object with the same keys, but with the promises replaced by their resolved values.

#### ✅ Example with mixed values
```ts
import { promiseAllObject } from 'promise-sos';

const promisesObject = {
  promiseA: Promise.resolve('resolved promiseA'),
  promiseB: Promise.resolve('resolved promiseB'),
  someValue: 1234,
  flag: true
};

const result = await promiseAllObject(promisesObject);

console.log(result);
// {
//   promiseA: 'resolved promiseA',
//   promiseB: 'resolved promiseB',
//   someValue: 1234,
//   flag: true
// }
```

#### ❌ Example with rejection
```ts
import { promiseAllObject } from 'promise-sos';

const promisesObject = {
  promiseA: Promise.reject(new Error('rejected promiseA')),
  promiseB: Promise.resolve('resolved promiseB')
};

try {
  const result = await promiseAllObject(promisesObject);
} catch (error) {
  console.error(error);
  // Error: rejected promiseA
}
```

---

## 📘 API

### `promiseAllObject<T>(promisesMap: T): Promise<PromisesMapResult<T>>`

- **`promisesMap`**: An object whose values may be promises or regular values.
- **Returns**: A promise resolving to an object with the same keys, with all promises unwrapped.
- **Throws**:
  - `TypeError` if input is not a non-empty plain object.
  - Any error from a rejected promise.

---

## 📝 License

MIT © [Inaki Arroyo](http://inakiarroyo.com)

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