# promise-result

> Simple wrapper for promise results.

Latest version **1.1.2** (published 2022-02-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2022-02-04 |
| First published | 2019-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Wouter van Heeswijk |
| Maintainers | woutervh- |

## Links

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

## Recent versions

- 1.1.2 (latest) — 2022-02-04
- 1.1.1 — 2019-09-24
- 1.1.0 — 2019-09-24
- 1.0.0 — 2019-08-02

## README

# promise-result
Simple wrapper for promise results with status.

## Installation

```shell
npm install --save promise-result
```

## Example

Basic usage:

```typescript
import { PromiseResult, pending, createFulfilled, createRejected, isFulfilled, isPending, isRejected } from 'promise-result';


let state: PromiseResult<string> = pending;

const myPromise = fetch('https://example.org/')
  .then(() => {
      state = createFulfilled('Everything is OK!');
  })
  .catch((error) => {
      state = createRejected(error);
  });

function doSomethingWithState() {
    if (isFulfilled(state)) {
        // Show user the result...
        show(state.result);
    }

    if (isPending(state)) {
        // Show user a loading icon...
        show(loading);
    }

    if (isRejected(state)) {
        // Show error message to user...
        show(state.error.message);
    }
}

```

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