1.0.1 • Published 9 years ago

cbp v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

cbp

Yet another callback to promise converter.

Build Status Dependencies Dev Dependencies

INSTALLATION

Everyone know how to do this:

npm install cbp --save

USAGE

cbp can argument as a function, an object, or a string.

If given function, cbp will tranform the function to a function that return a promise:

const fs  = require('fs');
const cbp = require('cbp');

const readFile = cbp(fs.readFile);
readFile('./package.json')
  .then(buf => console.log(buf))
  .catch(err => console.error(err));

If given an object, cbp will do like what it does to a function on every member if that member is a function. And, you still have access to the original function with prefix __:

const fs  = require('fs');
const cbp = require('cbp');

const fsp = cbp(fs);
fsp.readFile('./package.json')
  .then(buf => console.log(buf))
  .catch(err => console.error(err));

// accessing original function with prefix __
fsp.__readFile('./package.json', (err, buf) => {
  if (err) return console.error(err);
  console.log(buf);
});

And if given a string, cbp will do like what it does to an object by doing require first.

const cbp = require('cbp');
const fs  = cbp('fs');

fs.readFile('./package.json')
  .then(buf => console.log(buf))
  .catch(err => console.error(err));

LICENSE

MIT