Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

promise-or-cb

isysd4MIT1.1.0TypeScript support: included

Support both callback and promise style functions.

promise, callback, async

readme

promise-or-cb

Build Status Coverage Status

Support both Promises and callbacks for your code. Simply wrap your response with this function and pass the optional callback parameter. If callback is not defined, a Promise will be returned. Otherwise, the Promise will be resolved or rejected to the callback function, using standard (err, result) style. Works with both legacy .success and .error style Promises as well as modern .then and .catch syntax.

This library has no dependencies.

Install

npm i promise-or-cb

Usage

var porcb = require('promise-or-cb')

function flexible(arg, cb) {
  return porcb(new Promise((resolve, reject) => {
    if (arg === 'good') resolve(arg)
    else reject(arg)
  }, cb)
}

Credit

This project started as a fork of unpromise, which appears abandoned. Since the code was completely rewritten with new features, I consider it orginal IP at this point. Still, at least one test case was copied from that project, and Sugendran Ganess deserves credit.

Both projects are licensed MIT.