simple-switch

1.0.0 • Public • Published

simple-switch

Easily switch between callbacks and Promises.

  • Only 28 LOC.
  • No dependencies.
  • 100% test coverage.
  • Wraps Errors.
  • Requires Node 6+.

Installation

npm i -S simple-switch

Quickstart

promisifiy:

 
const { promisify } = require('simple-switch')
 
const sum = (a, b, cb) => {
    cb(false, a + b)
}
 
const promisifiedSum = promisify(sum)
 
promisifiedSum(1, 2).then(sum => {
    console.log(sum) // => 3
})
 

callbackify:

 
const { callbackify } = require('simple-switch')
 
const sum = (a, b) => {
    return Promise.resolve(+ b)
}
 
const callbackifiedSum = callbackify(sum)
 
callbackifiedSum(1, 2, sum => {
    console.log(sum) // => 3
})
 

License

WTFPL – Do What the F*ck You Want to Public License.

Made with ❤️ by @MarkTiedemann.

Package Sidebar

Install

npm i simple-switch

Weekly Downloads

1

Version

1.0.0

License

WTFPL

Last publish

Collaborators

  • marktiedemann