# hoper

> ```ts import { hope } from '../index';

Latest version **1.0.8** (published 2022-07-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install hoper
pnpm add hoper
yarn add hoper
bun add hoper
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2022-07-13 |
| First published | 2020-04-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nobody.codes, antonio.presto |

## Links

- npm: https://www.npmjs.com/package/hoper
- npm.io page: https://npm.io/package/hoper

## Recent versions

- 1.0.8 (latest) — 2022-07-13
- 1.0.7 — 2022-07-13
- 1.0.6 — 2022-07-13
- 1.0.5 — 2022-07-13
- 1.0.4 — 2021-06-18
- 1.0.3 — 2021-06-18
- 1.0.2 — 2021-06-18
- 1.0.1 — 2020-04-12
- 1.0.0 — 2020-04-12

## README

```ts
import { hope } from '../index';

describe('hope promises', () => {
  it('should call once', async () => {
    const hopes = hope();

    let callCount = 0;

    const result = await hopes.once(async () => {
      callCount++;
      return 1;
    });

    const result2 = await hopes.once(async () => {
      callCount++;
      return 2;
    });

    const result3 = await hopes.once(async () => {
      callCount++;
      return 3;
    });

    expect(result).toBe(1);
    expect(result2).toBe(1);
    expect(result3).toBe(1);
    expect(callCount).toBe(1);
  });

  it('should reject once', async () => {
    const hopes = hope();

    let callCount = 0;

    hopes.once(async () => {
      callCount++;
      return await Promise.reject('buu');
    });

    let err = '';
    try {
      await hopes.once(async () => {
        callCount++;
        return 3;
      });
    } catch (e) {
      err = e;
    }

    expect(callCount).toBe(1);
    expect(err).toBe('buu');
  });

  it('should resolve with .resolve', async () => {
    const hopes = hope();

    hopes.resolve(1);

    const result = await hopes.promise;

    expect(result).toBe(1);
  });

  it('should reject with .reject', async () => {
    const hopes = hope();

    hopes.reject(1);

    let err = '';
    try {
      await hopes.promise;
    } catch (e) {
      err = e;
    }

    expect(err).toBe(1);
  });
});
``;
```

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