# promesa

> easiest way to return a promise from a function

Latest version **0.1.1** (published 2013-12-06) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2013-12-06 |
| First published | 2013-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | jden |
| Maintainers | jden |
| Keywords | promise, promises/a+ |

## Links

- npm: https://www.npmjs.com/package/promesa
- Repository: git@github.com:jden/promesa
- Homepage: https://github.com/jden/promesa
- Issues: https://github.com/jden/promesa/issues
- npm.io page: https://npm.io/package/promesa

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) ~0.11.5-0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2013-12-06
- 0.1.0 — 2013-09-20

## README

# promesa
easiest way to return a promise from a function

*"promesa" is Spanish for "promise"*

## usage
```js
var Promesa = require('promesa')

// (Number) => Promise<User>
function getUser(id) {
  return Promesa(function () {
    if (!(typeof id === 'number' && Number.isFinite(id) && !Number.isNaN(id))) {
      throw new TypeError('id must be a number')
    }

    return {id: id, name: 'Boris Yeltsin'}
  })
}
```
In a real implementation, you would probably have some sort of
underlying asynchronous value, like a database lookup.

`Promesa` lets you mix and match returning Promise values,
synchronous values, and throwing. As explained in
[You're missing the point of promises][1], Promises/A+ lets
you reason about your code in terms of `return` and `throw`
semantics you already know and love.

[1]: https://gist.github.com/domenic/3889970

## FAQ

### When should I use `promesa` instead of another way of making a promise?

Promesa is ideal for making functions which are working with other promises as well as synchronous logic, for example precondition (guard) checking, authorization logic, etc. It assumes that any asynchronous values you're working with are already represented as Promises.

If you need to create promises from other kinds of asynchronous control flow patterns, such as EventEmitters or callback continuations, consider using something like `bluebird`'s `Promise` constructor.

## api

### `promesa: (fn: Function<T>) => Promise<T>`

Invokes the function `fn` and wraps the result in a Promise.
If `fn` returned a Promise, that value will be flattened and returned
(see the [Promise Resolution Procedure][2]). If `fn` returned a
value, a resolved Promise of that value will be returned. If `fn`
throws, a rejected Promise will be returned.

[2]: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure

## installation

    $ npm install promesa


## running the tests

From package root:

    $ npm install
    $ npm test


## contributors

- jden <jason@denizac.org>


## license

MIT. (c) MMXIII jden <jason@denizac.org>. See LICENSE.md

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