# afterward

> Execute an error-first callback upon resolution or rejection of a promise (and return the promise)

Latest version **2.1.0** (published 2015-11-13) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.1.0 |
| Published | 2015-11-13 |
| First published | 2015-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jason Pincin |
| Maintainers | jasonpincin |
| Keywords | promise, callback, resolve, reject |

## Links

- npm: https://www.npmjs.com/package/afterward
- Repository: https://github.com/jasonpincin/afterward
- Issues: https://github.com/jasonpincin/afterward/issues
- npm.io page: https://npm.io/package/afterward

## Dependencies (1)

- [define-error](https://npm.io/package/define-error.md) ~1.1.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2015-11-13
- 2.0.0 — 2015-09-11
- 1.0.2 — 2015-08-24
- 1.0.1 — 2015-08-22
- 1.0.0 — 2015-07-10

## README

# afterward

[![NPM version](https://badge.fury.io/js/afterward.png)](http://badge.fury.io/js/afterward)
[![Build Status](https://travis-ci.org/jasonpincin/afterward.svg?branch=master)](https://travis-ci.org/jasonpincin/afterward)
[![Coverage Status](https://coveralls.io/repos/jasonpincin/afterward/badge.png?branch=master)](https://coveralls.io/r/jasonpincin/afterward?branch=master)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/jp-afterward.svg)](https://saucelabs.com/u/jp-afterward)

Execute an error-first callback upon resolution or rejection of a promise, and return the promise.

This makes it easier to write functions that support both callback and promise based async patterns.

## example

```javascript
var afterward = require('afterward'),
    Promise   = require('promise-polyfill')

function greet (name, cb) {
    var prom = new Promise(function (resolve) {
        setTimeout(resolve.bind(undefined, 'greetings ' + name), 100)
    })
    return afterward(prom, cb)
}

// we can now use our fancy function either way...
// with a callback:
greet('jason', function (err, msg) {
    if (err) return console.error(err)
    console.log(msg)
})

// or a promise
greet('gege').then(console.log).catch(console.error)
```

## api

```javascript
var afterward = require('afterward')
```

### prom = afterward(prom [, cb])

Upon resolution or rejection of the promise `prom`, execute the optional error-first style callback `cb`. The promise `prom` is returned.

### errors

```javascript
var UnknownError = require('afterward/errors').UnknownError
```

#### UnknownError

The constructor function of the `Error` object provided to callback `cb` when the Promise `prom` is rejected with no argument.

## testing

`npm test [--dot | --spec] [--phantom] [--grep=pattern]`

Specifying `--dot` or `--spec` will change the output from the default TAP style. 
Specifying `--phantom` will cause the tests to run in the headless phantom browser instead of node.
Specifying `--grep` will only run the test files that match the given pattern.

### browser test

`npm run browser-test`

This will run the tests in all browsers (specified in .zuul.yml). Be sure to [educate zuul](https://github.com/defunctzombie/zuul/wiki/cloud-testing#2-educate-zuul) first.

### coverage

`npm run coverage [--html]`

This will output a textual coverage report. Including `--html` will also open 
an HTML coverage report in the default browser.

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