1.0.0 • Published 6 years ago
bakayaro v1.0.0
Bakayaro
Promsify your functions, bakayaro!
Installation
npm install bakayaro
Usage
Promisifes all
const {bakayaro} = require('bakayaro');
const fs = bakayaro(require('fs'), 'Yaro'); // You can change 'Yaro' to anything you want.
/* Notice the new function will have suffix you've defined.
By default, it will have suffix of 'Async'.
*/
/* Use promisified readFile function with .then and .catch */
fs.readFileYaro('text.txt').then(text => console.log(text)).catch(err => console.log(err));
/* Use with async/await */
try {
const text = await fs.readFileYaro('text.txt');
console.log(text);
} catch(err) {
console.log(err);
}
Promisifies a function
const {baka} = require('bakayaro');
const fs = require('fs');
const readFileYaro = baka(fs.readFile);
/* Use promisified readFile function */
readFileYaro('text.txt').then(text => console.log(text)).catch(err => console.log(err));
/* With async/await */
try {
const text = await readFileYaro('text.txt');
console.log(text)
} catch(err) {
console.log(err);
}
1.0.0
6 years ago