async-callback-promise-wrapper
v1.0.7
Published
Wraps any method that takes a callback to return a promise
Downloads
1
Maintainers
Readme
async-callback-promise-wrapper
Wraps any method that takes a callback to return a promise
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.
Installation
Package Manger
Using npm:
npm i async-callback-promise-wrapper
Documentation
Cjs Module
const MethodWrapper = require('async-callback-promise-wrapper')
Usage
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,...);
Options
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}
Supports
- commonjs
- node.js
Development
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.
License
MIT
Don't forget to Star on Github!