simple-switch
v1.0.0
Published
Easily switch between callbacks and Promises.
Downloads
6
Maintainers
Readme
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(a + 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 :heart: by @MarkTiedemann.