{"name":"@gar/promisify","version":"1.1.0","description":"Promisify an entire class or object","main":"index.js","repository":{"type":"git","url":"git+https://github.com/wraithgar/gar-promisify.git"},"scripts":{"lint":"standard","lint:fix":"standard --fix","test":"lab -a @hapi/code -t 100","posttest":"npm run lint"},"keywords":["promisify","all","class","object"],"author":{"name":"Gar","email":"gar+npm@danger.computer"},"license":"MIT","devDependencies":{"@hapi/code":"^8.0.1","@hapi/lab":"^24.1.0","standard":"^16.0.3"},"gitHead":"adb0ee07489f06b0368a8bd38ba25b1b8f54b74d","bugs":{"url":"https://github.com/wraithgar/gar-promisify/issues"},"homepage":"https://github.com/wraithgar/gar-promisify#readme","_id":"@gar/promisify@1.1.0","_nodeVersion":"14.17.1","_npmVersion":"7.20.0","dist":{"integrity":"sha512-LcI350vbmmc7NI2e6GI3l8+GFx+HIxL3t8dwC6tpfTZHLQfpwAyULRXCbX74tIRLoLSRAYUyN7Dbv1coU/pIDA==","shasum":"ec6d35d9f2d91a7415a2bcfc815235488f9103cf","tarball":"http://registry-npm.ywwl.com/@gar/promisify/download/@gar/promisify-1.1.0.tgz","fileCount":3,"unpackedSize":3018,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg+HiyCRA9TVsSAnZWagAATm0P/j+0FhmaL995oHS3suxJ\nypLCBn8/qs6y0rXAZLYGA9sb6IRi/Bf3YYv7xnkxXARunZq7UmY9iHukR1hA\n0QoEXSRH97iu9QKF7NoSls1n2xhPvzobwwZoOexXt27pvjAdI0dz0L/pXHqT\nkEdvxYs+bz82UaICrJ/BROBYskVqdnPpFDpPkiW1J26tTG4CFnqyhxLdtIf8\nTJvrDK3kEQ/6AUox+7plxM5u/ZM4D8Mlg4hKEOJ/7xV7Z3/cgdEZZ5JWzie5\nICUghnx/OeZ9L1yGDNt//UlzkdCGlGAHXnEM5ZDwsewtui8OVFkhTb6hL8nV\nYoK8Iyuyqz5H4JaazLb4Xs1rfnYCccF5yJZzrNz+d7BT1HM7FOW2IyggE7sv\nYDU29RUHe7SShfopao9EafrIqd6y6oxqNIC1NzYa+9act84MD7oGMGGRVN2D\niCpXS44Jet6ztvTccTFK9CJDKPTEa4C/5bW2L0HdvnjF3b+4PE7UUTmpbqN9\nKGhVJZ/RzEUy/n/yGv/Dlv0LIrB+h1KsmEpMXN5hOFm5Y5+otH7bABuYXup+\nSrBjZfG/obsrD9dvHAkY0oy2ccTeXt/AVk5rp1kGd9PE8rrHtEAfLVNyF6HR\nqo/sZQeoS7d0MGcXKOmJcm1vHxSe5OcBmeWOEn6RpSuD3JM9y5VJylUV244y\nXFrb\r\n=/N8e\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCJ3OnQ9rQZK2UmuceB7Du969G9kSLpMmFzcj33i2LK+AIhALzpFGngL2E4EHn5uDG77ViwW4LWfElJWT3tYm2AF8KG"}],"size":1411,"noattachment":false,"key":"/@gar/promisify/-/@gar/promisify-1.1.0.tgz"},"_npmUser":{"name":"gar","email":"gar+npm@danger.computer"},"directories":{},"maintainers":[{"name":"gar","email":"gar+npm@danger.computer"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/promisify_1.1.0_1626896561921_0.7174857668707793"},"_hasShrinkwrap":false,"readme":"# @gar/promisify\n\n### Promisify an entire object or class instance\n\nThis module leverages es6 Proxy and Reflect to promisify every function in an\nobject or class instance.\n\nIt assumes the callback that the function is expecting is the last\nparameter, and that it is an error-first callback with only one value,\ni.e. `(err, value) => ...`. This mirrors node's `util.promisify` method.\n\nIn order that you can use it as a one-stop-shop for all your promisify\nneeds, you can also pass it a function.  That function will be\npromisified as normal using node's built-in `util.promisify` method.\n\n[node's custom promisified\nfunctions](https://nodejs.org/api/util.html#util_custom_promisified_functions)\nwill also be mirrored, further allowing this to be a drop-in replacement\nfor the built-in `util.promisify`.\n\n### Examples\n\nPromisify an entire object\n\n```javascript\n\nconst promisify = require('@gar/promisify')\n\nclass Foo {\n  constructor (attr) {\n    this.attr = attr\n  }\n\n  double (input, cb) {\n    cb(null, input * 2)\n  }\n\nconst foo = new Foo('baz')\nconst promisified = promisify(foo)\n\nconsole.log(promisified.attr)\nconsole.log(await promisified.double(1024))\n```\n\nPromisify a function\n\n```javascript\n\nconst promisify = require('@gar/promisify')\n\nfunction foo (a, cb) {\n  if (a !== 'bad') {\n    return cb(null, 'ok')\n  }\n  return cb('not ok')\n}\n\nconst promisified = promisify(foo)\n\n// This will resolve to 'ok'\npromisified('good')\n\n// this will reject\npromisified('bad')\n```\n","publish_time":1626896562076,"_cnpm_publish_time":1626896562076,"dist-tags":{"latest":"1.1.3","test":"1.0.0"}}