# @fizzygalacticus/promise-or-not

> Perform an action on the result of a function, synchronously or asyncronously.

Latest version **2.0.0** (published 2020-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fizzygalacticus/promise-or-not
pnpm add @fizzygalacticus/promise-or-not
yarn add @fizzygalacticus/promise-or-not
bun add @fizzygalacticus/promise-or-not
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-07-27 |
| First published | 2019-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dustin L. Dodson |
| Maintainers | fizzygalacticus |
| Keywords | regardless, if, promise, not |

## Links

- npm: https://www.npmjs.com/package/@fizzygalacticus/promise-or-not
- Repository: https://github.com/FizzyGalacticus/promise-or-not
- npm.io page: https://npm.io/package/@fizzygalacticus/promise-or-not

## Dependencies (1)

- [@fizzygalacticus/is-promise](https://npm.io/package/@fizzygalacticus/is-promise.md) ^1.0.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-07-27
- 1.0.3 — 2019-08-31
- 1.0.2 — 2019-08-30
- 1.0.1 — 2019-08-28
- 1.0.0 — 2019-08-28

## README

# promise-or-not

`promise-or-not` is a function decorator that can act as a middleman to perform operations on resulting data, even if the function initially returns a promise.

## Installation

`yarn add @fizzygalacticus/promise-or-not` || `npm i --save @fizzygalacticus/promise-or-not`

## Usage

**Parameters:**
* `fn` - The primary function you wish to run
* `onData` - The function to call when data is received
* `onError` - The function to call when an error occurrs
* `returnPromise` - Forces even synchronous functions to return a `Promise`. This can be useful in situations where you may want to make multiple calls to `promise-or-not` as I do in my [savethis](https://github.com/FizzyGalacticus/savethis) project.

For synchronous functions:
```js

const promiseOrNot = require('@fizzygalacticus/promise-or-not');

const mySyncFn = i => 'some return value ' + i;

const decorated = promiseOrNot(mySyncFn, val => console.log(val));

const val = decorated(1); // will print `1`
console.log(val) // `1`

```

For asynchronous functions:
```js

const promiseOrNot = require('@fizzygalacticus/promise-or-not');

const mySyncFn = i => Promise.resolve('some return value ' + i);

const decorated = promiseOrNot(mySyncFn, val => console.log(val));

decorated(1).then(console.log); // will print `1` twice

```

## Why?

This was initially written for my [trythis](https://github.com/FizzyGalacticus/trythis) library, which just prints the return value of a wrapped function (such as the example above). I then realized that this would be very handy to abstract away for other, potentially similar use cases.

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