# @alexbinary/promisify

> Naive promisification 🙈

Latest version **3.0.4** (published 2016-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alexbinary/promisify
pnpm add @alexbinary/promisify
yarn add @alexbinary/promisify
bun add @alexbinary/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 | 3.0.4 |
| Published | 2016-12-29 |
| First published | 2016-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexandre Bintz |
| Maintainers | alexbinary |
| Keywords | promise, promises, promisify, promisification, async |

## Links

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

## 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

- 3.0.4 (latest) — 2016-12-29
- 3.0.3 — 2016-12-29
- 3.0.2 — 2016-12-28
- 3.0.1 — 2016-12-27
- 3.0.0 — 2016-12-27

## README

# promisify

Naive promisification 🙈

[![npm](https://img.shields.io/npm/v/@alexbinary/promisify.svg)](https://www.npmjs.com/package/@alexbinary/promisify)
[![GitHub release](https://img.shields.io/github/release/alexbinary/promisify.svg?label="github")](https://github.com/alexbinary/promisify/releases/latest)
[![Build Status](https://travis-ci.org/alexbinary/promisify.svg)](https://travis-ci.org/alexbinary/promisify)
[![dependencies Status](https://david-dm.org/alexbinary/promisify/status.svg)](https://david-dm.org/alexbinary/promisify)
[![devDependencies Status](https://david-dm.org/alexbinary/promisify/dev-status.svg)](https://david-dm.org/alexbinary/promisify?type=dev)

WARNING: This is a very basic implementation that works in simple cases but will probably break in more advanced situations.

## Install

Install using npm or yarn :

```bash
$ npm install @alexbinary/promisify
# or
$ yarn add @alexbinary/promisify
```

## Usage

```javascript
let promisify = require('@alexbinary/promisify')

// promisify a function :

function f (cb) { cb(null, 'ok') }

promisify(f)()
.then((result) => console.log(result))  // 'ok'
.catch((err) => console.error(err))

// promisify methods in an object :

promisify(fs, ['readFile', 'writeFile'])
fs.readFile('/foo/bar', 'utf8')
.then((content) => console.log(content))
.catch((err) => console.log(err))

```

## Documentation

```javascript
let promisify = require('@alexbinary/promisify')
```

### promisify(function)

Returns a function that returns a Promise with `function` as its executor.

`function` is expected to take a callback as last argument and call it with an error as first argument or null if success (node callback style).

If the callback is called with an error then the promise gets rejected with that error.
If the callback is called without error then the promise is resolved with any arguments passed to the callback after the first argument.

Note that the returned function can still be used with a callback style.

This method is idempotent, i.e. if `function` is the result of calling `promisify` then the returned value is `function` itself. This is done by defining a Symbol property on the returned object and checking for that property before processing.

### promisify(object, methods)

Replaces methods in given `object` whose names are listed in `methods` by the result of `promisify(method)`.

Returns `object`.

## License

MIT

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