1.3.2 • Published 9 years ago
decb v1.3.2
decb
decb is a module that translates modules to a promisified version of them. Note that it is not possible to differentiate between asynchronous and synchronous functions, so (if needed) it has do be done manually.
Code Example
Use fs.readFile with Promises:
const decb = require('decb');
const fs = decb(require('fs'));
fs.readFile('example.js', 'utf8').then(file => {
console.log(file);
});
console.log(fs.readFileSync('example.js', 'utf8'));
//Returns a promise and does not workUse fs.readFile with Promises, but don't translate fs.readFileSync
const decb = require('decb');
const fs = decb(require('fs'), {
ignore: ['readFileSync']
});
fs.readFile('example.js', 'utf8').then(file => {
console.log(file);
});
console.log(fs.readFileSync('example.js', 'utf8'));
//Works as expectedUse fs.readFile with Promises, but don't change the rest of the module
const decb = require('decb');
const fs = decb(require('fs'), {
use: ['readFile']
});
fs.readFile('example.js', 'utf8').then(file => {
console.log(file);
});
console.log(fs.readFileSync('example.js', 'utf8'));
console.log(fs.readdirSync('lib'));
//Works as expectedInstallation
$ npm install decb
API
###decb(module,config)
- module: an npm module to translate
- config: a config object with either an
ignoreoruseproperty
Returns a promisified version of the module
License
MIT