Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

@gar/promisify

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Issues
File Explorer

Advanced tools

@gar/promisify

Promisify an entire class or object

    1.1.3latest

Version published
Maintainers
1
Weekly downloads
9,201,219
decreased by-11.33%

Weekly downloads

Readme

Source

@gar/promisify

Promisify an entire object or class instance

This module leverages es6 Proxy and Reflect to promisify every function in an object or class instance.

It assumes the callback that the function is expecting is the last parameter, and that it is an error-first callback with only one value, i.e. (err, value) => .... This mirrors node's util.promisify method.

In order that you can use it as a one-stop-shop for all your promisify needs, you can also pass it a function. That function will be promisified as normal using node's built-in util.promisify method.

node's custom promisified functions will also be mirrored, further allowing this to be a drop-in replacement for the built-in util.promisify.

Examples

Promisify an entire object

const promisify = require('@gar/promisify') class Foo { constructor (attr) { this.attr = attr } double (input, cb) { cb(null, input * 2) } const foo = new Foo('baz') const promisified = promisify(foo) console.log(promisified.attr) console.log(await promisified.double(1024))

Promisify a function

const promisify = require('@gar/promisify') function foo (a, cb) { if (a !== 'bad') { return cb(null, 'ok') } return cb('not ok') } const promisified = promisify(foo) // This will resolve to 'ok' promisified('good') // this will reject promisified('bad')

Keywords

FAQs

What is @gar/promisify?

Promisify an entire class or object

Is @gar/promisify popular?

The npm package @gar/promisify receives a total of 7,431,227 weekly downloads. As such, @gar/promisify popularity was classified as popular.

Is @gar/promisify well maintained?

We found that @gar/promisify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 16 Feb 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc