async-callback-promise-wrapper is a swift wrapper that will wrap around your favourite function that requires a callback, and will return a method that returns a promise.
Using npm:
npm i async-callback-promise-wrapper
const MethodWrapper = require('async-callback-promise-wrapper')
Referring the method to be wrapped as exampleMethod
exampleMethod(input1, input2,..., callback);
Wrapping the exampleMethod.
const wrappedMethod = MethodWrapper(exampleMethod);
or
const wrappedMethod = MethodWrapper(exampleMethod,{...options});
Using the wrapped method.
let receivedPromise = wrappedMethod(input1, input2,...);
The method to be wrapped takes the input
arguments first and then the callback
exampleMethod(input1,input2,...,callback)
then leave paramsOrder
as undefined or provide paramsOrder:true
in options
options = { ...otherOptions, paramsOrder:true}
The method to be wrapped takes the callback
first and then the input
arguments
exampleMethod(callback, input1, input2)
then provide paramsOrder:false
in options
options = { ...otherOptions, paramsOrder:false}
The callback is required to take the result
as first argument and the error
as second argument
callback(res, err)
then leave callbackParamsOrder
as undefined or provide callbackParamsOrder:true
in options
options = {...otherOptions, callbackParamsOrder:true}
The callback is required to take the error
as first argument and the result
as second argument
callback(err, res)
then provide callbackParamsOrder:false
in options
options = {...otherOptions, callbackParamsOrder:false}
The callback is required to take only the result
. The method to be wrapped throws any errors
directly.
callback(res);
exampleMethod(input1, input2, callback) throws Error
then leave callbackParamsOrder
as undefined or provide callbackParamsOrder:true
in options
options = {...otherOptions, callbackParamsOrder:true}
- commonjs
- node.js
Want to contribute? Great!
async-callback-promise-wrapper is build using the latest technologies
Open your favorite Terminal and run these commands.
Install Dependencies
npm install
Run Tests
npm run test
Build
npm run build
Distribution files are present in the build
folder.
MIT
Don't forget to Star on Github!