c2p
let callback style function return promise
Installation
$ npm install c2p
Example
let's make fs.access as an example.
we should use like fs.access(path[, mode], callback)
fs.access('/etc/passwd', fs.constants.R_OK | fs.constants.W_OK, (err) => {
console.log(err ? 'no access!' : 'can read/write');
});
we can convert this style functions return promise.
import c2p from 'c2p'
try {
await c2p(fs.access, '/etc/passed', fs.constants.R_OK | fs.constants.W_OK);
console.log('can read/write')
} catch (e) => {
console.log(err + 'no access!')
}
api
c2p(functionName, ...args)
functionName
: the function you want to convert.args
: the origin function arguments except callback function..
License
MIT