# catering

> Simple utility to allow your module to be consumed with a callback or promise

Latest version **2.1.1** (published 2022-01-14) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2022-01-14 |
| First published | 2018-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Vincent Weevers |
| Maintainers | vweevers |
| Keywords | callback, promise, promisify |

## Links

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

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

- 2.1.1 (latest) — 2022-01-14
- 2.1.0 — 2021-10-02
- 2.0.0 — 2020-03-27
- 1.0.0 — 2018-09-01

## README

# catering

**Cater to callback and promise crowds.**  
Simple utility to allow your module to be consumed with a callback or promise. For Node.js and browsers.

[![npm status](https://img.shields.io/npm/v/catering.svg)](https://www.npmjs.com/package/catering)
[![Node version](https://img.shields.io/node/v/catering.svg)](https://www.npmjs.com/package/catering)
[![Test](https://img.shields.io/github/workflow/status/vweevers/catering/Test?label=test)](https://github.com/vweevers/catering/actions/workflows/test.yml)
[![Standard](https://img.shields.io/badge/standard-informational?logo=javascript&logoColor=fff)](https://standardjs.com)

## Menu

If your module internally uses callbacks:

```js
const { fromCallback } = require('catering')
const kPromise = Symbol('promise')

module.exports = function (callback) {
  callback = fromCallback(callback, kPromise)
  queueMicrotask(() => callback(null, 'example'))
  return callback[kPromise]
}
```

If your module internally uses promises:

```js
const { fromPromise } = require('catering')

module.exports = function (callback) {
  return fromPromise(Promise.resolve('example'), callback)
}
```

Either way your module can now be consumed in two ways:

```js
example((err, result) => {})
const result = await example()
```

When converting from a promise to a callback, `fromPromise` calls the callback in a next tick to escape the promise chain and not let it steal your beautiful errors.

## Install

With [npm](https://npmjs.org) do:

```
npm install catering
```

## License

[MIT](LICENSE) © 2018-present Vincent Weevers. Originally extracted from [`levelup`](https://github.com/Level/levelup/blob/37e0270c8c29d5086904e29e247e918dddcce6e2/lib/promisify.js).

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