1.1.0 • Published 6 years ago

promise-or-cb v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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.