prominence
v0.2.0
Published
Call a callback-based function as ES6 Promise
Downloads
24
Readme
prominence
Call a callback-based function as ES6 Promise
Installation
NPM
npm install prominence
API
prominenct(context: object): Prominence
prominence(context: object, methodName: string, [ args: any[] ]): Promise<any>
Examples
ES6 Promise
import fs from "fs";
import prominence from "prominence";
// use Prominence proxy
prominence(fs).readFile(filepath, "utf-8").then((text) => {
console.log(text);
}).catch(console.error.bind(console));
// not use a proxy
prominence(fs, "readFile", [ filepath, "utf-8" ]).then((text) => {
console.log(text);
}).catch(console.error.bind(console));
ES7 Async/Await
import fs from "fs";
import prominence from "prominence";
// use Prominence Proxy
async (filepath) => {
let text = await prominence(fs).readFile(filepath, "utf-8");
console.log(text);
};
// not use a proxy
async (filepath) => {
let text = await prominence(fs, "readFile", [ filepath, "utf-8" ]);
console.log(text);
};
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D