c2p

0.0.3 • Public • Published

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

Package Sidebar

Install

npm i c2p

Weekly Downloads

1

Version

0.0.3

License

ISC

Last publish

Collaborators

  • kehanshi