# safer-promise

> A Promise that cannot be observed.

Latest version **0.2.1** (published 2019-06-03) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-06-03 |
| First published | 2019-05-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | secure, function, call, apply, bind |

## Links

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

## Dependencies (2)

- [safer-class](https://npm.io/package/safer-class.md) ^0.2.1
- [safer-function](https://npm.io/package/safer-function.md) ^0.1.2

## Recent versions

- 0.2.1 (latest) — 2019-06-03
- 0.2.0 — 2019-05-16
- 0.1.2 — 2019-05-15
- 0.1.1 — 2019-05-15
- 0.1.0 — 2019-05-14
- 0.0.0 — 2019-05-14

## README

# safer-promise

<sup>**Social Media Photo by [freestocks.org](https://unsplash.com/@freestocks) on [Unsplash](https://unsplash.com/)**</sup>

[![Build Status](https://travis-ci.com/WebReflection/safer-promise.svg?branch=master)](https://travis-ci.com/WebReflection/safer-promise) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/safer-promise/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/safer-promise?branch=master) ![WebReflection status](https://offline.report/status/webreflection.svg)


A Promise that cannot be observed, with `resolve` and `reject` methods able to secure other promises too.

```js
// once imported
import SaferPromise, {resolve, reject} from 'safer-function';

// even nasty operations like this would not interfere
const {then} = Promise.prototype;
Object.defineProperties(Promise.prototype, {
  then: {
    value(fn) {
      return typeof fn === 'function' ?
        then.call(this, result => {
          console.log('BUSTED', result);
          return fn(result);
        }) :
        then.call(this, fn, result => {
          console.log('BUSTED', result);
          return result;
        });
    }
  }
});
Object.freeze(Promise);
Object.freeze(Promise.prototype);

// try it to believe it
resolve(123).then(console.log).then(console.log).catch(console.log);

// or even with native promises, i.e.
resolve(fetch('file')).then(...);

```

## Compatibility

The compatibility bar here is defined by a native `Symbol.species` entity, meaning that every ES2015 engine should work as expected.

This module is specially handy to secure advanced modern features so that old browsers will never be a target goal.

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