# tiny-promisify

> Tiny library to promisify functions expecting node-style callbacks

Latest version **1.0.0** (published 2016-10-18) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install tiny-promisify
pnpm add tiny-promisify
yarn add tiny-promisify
bun add tiny-promisify
```

## 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 | 1.0.0 |
| Published | 2016-10-18 |
| First published | 2015-11-26 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Gabriel Montes |
| Maintainers | gabmontes |
| Keywords | promise, promisify, callback, async, es6, node |

## Links

- npm: https://www.npmjs.com/package/tiny-promisify
- Repository: https://github.com/gabmontes/tiny-promisify
- Homepage: https://github.com/gabmontes/tiny-promisify#readme
- Issues: https://github.com/gabmontes/tiny-promisify/issues
- npm.io page: https://npm.io/package/tiny-promisify

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.11.6

## Alternatives

- [@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
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-10-18
- 0.1.1 — 2016-03-09
- 0.1.0 — 2015-11-26

## README

# Tiny Node Promisify

Minimalist library to promisify functions expecting node-style callbacks.

## Install

```bash
npm install tiny-promisify
```

## Usage

Given a `fn` that uses the node-style callbacks, expecting a callback as the last parameter and this callback expecting an `err` as the first parameter, you can obtain a new function that return promises as follows:

```javascript
var promisify = require('tiny-promisify');

function fn (args, callback) {
  // fn code here...
  callback(err, results);
}

var fnAsync = promisify(fn);
fnAsync(args).then(function (result) {
  // your code here...
}).catch(function (err) {
  // handle error here...
});
```

## API

### `promisify(fn, [options])`

* `fn` is a function that receives a callback as the last. argument. The callback will receive an `err` object as the first argument.
* `options` is an optional object having the following properties:
  * `multiArgs` set to `true` will make the promise resolve to an array containing all the parameters passed to the callback. Otherwise, only the first non-error parameter is passed to the promise success callback. Defaults to `false`.
  * `context` is the object uses as `this` when calling `fn`. Defaults to `{}`.

Returns a new function that wraps `fn` in a promise.

## Notes

The module uses Babel's polyfills for `Promise` and `Object.assign()` when not found in the current execution environment.

You can require the ES2015 version of the lib by specifying the source file: `require('tiny-promisify/lib')`.

## License

WTFPL

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