Socket
Socket
Sign inDemoInstall

catering

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    catering

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


Version published
Weekly downloads
150K
decreased by-14.09%
Maintainers
1
Install size
5.72 kB
Created
Weekly downloads
 

Readme

Source

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 Node version Test Standard

Menu

If your module internally uses callbacks:

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:

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:

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 do:

npm install catering

License

MIT © 2018-present Vincent Weevers. Originally extracted from levelup.

Keywords

FAQs

Last updated on 14 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc