# promisize

> Easily support both callbacks and promises in your js lib

Latest version **1.1.2** (published 2017-04-14) · MIT license · 0 weekly downloads

## Install

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

## 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.1.2 |
| Published | 2017-04-14 |
| First published | 2017-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | xuset |
| Maintainers | xuset |
| Keywords | defer, promise, callback |

## Links

- npm: https://www.npmjs.com/package/promisize
- Repository: https://github.com/xuset/promisize
- Homepage: https://github.com/xuset/promisize#readme
- Issues: https://github.com/xuset/promisize/issues
- npm.io page: https://npm.io/package/promisize

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

- 1.1.2 (latest) — 2017-04-14
- 1.1.1 — 2017-03-25
- 1.1.0 — 2017-03-25
- 0.0.0 — 2017-03-25
- 1.0.0 — 2017-03-25

## README

# promisize [![Build Status](https://travis-ci.org/xuset/promisize.svg?branch=master)](https://travis-ci.org/xuset/promisize) [![npm](https://img.shields.io/npm/v/promisize.svg)](https://npmjs.org/package/promisize)

#### Easily support both callbacks and promises in your js lib

**promisize** takes your function's callback argument and returns a new callback with a `promise` property. When the new callback is called, it either calls the original callback or if no callback was given it fulfills the promise. **promisize** is lightweight and does not include any promise shims or dependencies but instead uses the globally defined `Promise`. If `Promise` is not defined (i.e. no native promise support) then callbacks still work as they would without **promisize**.

## Usage

```js
var promisize = require('promisize')

function someAsyncFunction (cb) {
  cb = promisize(cb)

  // Do some async stuff then
  setTimeout(function () {
    cb(null, 'foobar')
  })

  // Undefined if there is no Promise support
  // or if the original callback was defined
  return cb.promise
}
```

## API

### `var cb = promisize(function callback (err, result) {})`

`promisize` takes a nodejs style callback and returns another nodejs style callback. When the returned callback is called it either calls the original callback or fulfills the promise but never both.

### `cb.promise`

The returned `cb` has a `promise` property that is only defined if the environment has Promise support (i.e. `Promise` is defined) and the original callback was undefined. When the returned callback is called it fulfills this promise if it is defined or calls the original callback if the promise is undefined.

## License

MIT. Copyright (c) Austin Middleton.

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