# angular-q-promisify

> Angular service for returning $q promises from callback APIs

Latest version **3.0.0** (published 2016-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install angular-q-promisify
pnpm add angular-q-promisify
yarn add angular-q-promisify
bun add angular-q-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.0 |
| Published | 2016-08-25 |
| First published | 2015-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | angular, $q, promise, promisify |

## Links

- npm: https://www.npmjs.com/package/angular-q-promisify
- Repository: https://github.com/bendrucker/angular-q-promisify
- Issues: https://github.com/bendrucker/angular-q-promisify/issues
- npm.io page: https://npm.io/package/angular-q-promisify

## Dependencies (3)

- [to-array](https://npm.io/package/to-array.md) ~0.1.4
- [browserify](https://npm.io/package/browserify.md) ~13.1.0
- [assert-function](https://npm.io/package/assert-function.md) ~1.0.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

- 3.0.0 (latest) — 2016-08-25
- 2.0.1 — 2016-07-31
- 2.0.0 — 2016-07-30
- 1.1.0 — 2015-09-06
- 1.0.0 — 2015-01-25

## README

# angular-q-promisify [![Build Status](https://travis-ci.org/bendrucker/angular-q-promisify.svg?branch=master)](https://travis-ci.org/bendrucker/angular-q-promisify)

Angular service for returning `$q` promises from callback APIs. Inspired by [Bluebird's promsification API](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification), angular-q-promsify uses `$q` to convert functions and objects that take callbacks into ones that return `$q` promises.

## Installing

```bash
$ npm install angular-q-promisify
```

## Setup

```js
// Service
angular.module('myApp', [
  require('angular-q-promisify')
])

// Decorator
angular.module('myApp', [
  require('angular-q-promisify/decorate')
])
```

Using the decorate module adds `promisify` and `promisifyAll` to `$q` instead of exposing a new service.


## API

**Service name:** `promisify`

##### `promisify(nodeback [, receiver])` -> `Function`

Accepts a `nodeback` (a callback with the signature `(err, args...)`) and returns a function that returns a `$q` promise instead. If the `nodeback` is called with more than 2 arguments, the values will be returned as an array. If the callback is called with an error (`err`) or throws an exception, the promise returned by the promisified function will become rejected.

If a `receiver` is passed, the `nodeback` will be called on it, so `this` will be the `receiver`.

Note that the promisification logic is dramatically less sophisticated than Bluebird's. The function's `length` property will not be preserved among other potential inconsistencies. Most simple cases will work.

```js
function getData (callback) {
  // ...
}
var getDataPromise = promisify(getData)
getDataPromise().then(handleData).catch(handleErr)
```

<hr>

##### `promisify.promisifyAll(object)` -> `object`

Promsifies all methods on an `object`, suffixing them with `'Async'`.

```js
var user = {
  getData: function (callback) {
    // ...
  }
}
promisify.promisifyAll(user)
user.getDataAsync().then(handleUserData).catch(handleUserErr)
```

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