promisify-func

0.0.7 • Public • Published

promisify-func

Make function async (i.e. if function returns not Promise then it wraps it with Promise; if function throws error then wrap it with Promise.reject).

Coverage Status Build Status

Example

const promisify = require('promisify-func');
 
const p = (url) => url;
 
promisify(p)(url).then(res => {
    //res == url
})
 
const t = () => {throw new Error()};
 
promisify(t)().catch(err => {
    //err == new Error()
})
 
//will do nothing for Promises
promisify(Promise.resolve("abc")).then(res => {
    //res == abc
})
 

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.7
    0
    • latest

Version History

Package Sidebar

Install

npm i promisify-func

Weekly Downloads

0

Version

0.0.7

License

MIT

Unpacked Size

7.2 kB

Total Files

6

Last publish

Collaborators

  • artemdudkin