{"_id":"a-callback","_rev":"1-6473401faac02dc38ad75ad407267414","name":"a-callback","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"a-callback","version":"0.1.1","description":"An utility to convert node callbacks to promise","author":{"name":"ty","email":"towyuan@outlook.com"},"license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=14"},"scripts":{"prerelease":"cross-env CI=1 npm run test","release":"np --no-2fa","build":"lb-tsc -b","build:full":"npm ci --ignore-scripts && npm run clean && npm run build","coverage":"lb-nyc report --reporter=text-summary","precoverage":"npm test","lint":"npm run prettier:check && npm run eslint","lint:fix":"npm run eslint:fix && npm run prettier:fix","eslint":"lb-eslint --report-unused-disable-directives --cache .","eslint:fix":"npm run eslint -- --fix","prettier:cli":"lb-prettier \"**/*.ts\" \"**/*.js\" \"**/*.md\"","prettier:check":"npm run prettier:cli -- --check","prettier:fix":"npm run prettier:cli -- --write","format":"npm run prettier:fix","clean":"lb-clean dist coverage .nyc_output *.tsbuildinfo","pretest":"npm run clean && npm run format","test":"lb-nyc npm run mocha","test:ci":"lb-nyc npm run mocha","posttest":"npm run lint","premocha":"npm run build","mocha":"lb-mocha --allow-console-logs \"dist/__tests__/**/*.js\"","preunit":"npm run build","unit":"lb-mocha --allow-console-logs \"dist/__tests__/unit/**/*.js\""},"dependencies":{},"devDependencies":{"@loopback/build":"^7.0.0","@loopback/eslint-config":"^11.0.0","@loopback/testlab":"^3.4.2","@types/mocha":"^9.0.0","@types/node":"^16.7.10","@typescript-eslint/eslint-plugin":"^4.30.0","@typescript-eslint/parser":"^4.30.0","cross-env":"^7.0.3","eslint":"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-eslint-plugin":"^3.5.3","eslint-plugin-mocha":"^9.0.0","eslint-plugin-prettier":"^4.0.0","mocha":"^9.1.1","np":"^7.5.0","prettier":"^2.3.2","typescript":"^4.4.2"},"keywords":["promise","async","callback","promisify"],"gitHead":"d97d433671c867feb67ba804c0d9338b1ad8c866","_id":"a-callback@0.1.1","_nodeVersion":"16.7.0","_npmVersion":"7.20.3","dist":{"integrity":"sha512-Wku8uypmrLtIwaJaYAi5kt0U/JPBi+N3286JzOtAn7SAAM2cmKlSQ/C7ZVzwp70IpssKasBm4ThQHDeWa6vZCw==","shasum":"bfaa3abee830b24678b911412a1b53f00f67b199","tarball":"https://registry.npmjs.org/a-callback/-/a-callback-0.1.1.tgz","fileCount":7,"unpackedSize":7297,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhNcWCCRA9TVsSAnZWagAATOkP/Rjwf0xCPEKFIe7n8Wwa\nQj2zrnRAeUqB8GZQ5OelHDtoHTOcGaapvh+VzR+znnCcsyiQdqe6y7DRcW+G\nZthvy3zS3GD02o+bVyl5EtQI2a8JSVWXpxYhJun7P0/cwVuNyWmKpiKSepsR\n6yc2aVNdYaIJvIQ0HA74HAb/OGQx57pJ75N70ruCGXKDZfeNeBFEwY1Y+oh0\nakToLztA8QIDaRGCUp7LOcv9fnyo/bgK3xgNttytfi2BKGGfRNATxOVa98du\nnOEZSLLvJIHFYEoF7AImEI8w3jB7T93lft8IWfbeWGsNQ0XLcEE9YztiDUFH\nfxMtg0L3QuP27xGv1tOsEJIYWUHXJ23doFhnM17/VY4M1XTHOwEImJDxmkKN\nSqKn+BGgEDTxBC0fJH0pGIxTQJGyZasK1Otdc4tmWBfKQPjW5O78GxQ4vRxb\ngAnfJ2tLRwfZJIZkWpLzXB1puH69Rg3DLEzBEpkeLCYqvgc98bzgjk4s9h2i\nfVo2Muy2jMJBQ6oTrVInb6Ugsecyl3aO7kdtRORuk0sH+JE9Yd9SnxZTBvZx\n32VU7y503dj84OcK7AzF0xK0RkzyYBt5ZZOxsTLDDavXK8oGykCfoLkBBPdU\n5Bl9cLVlSjQadXb0l/WeUSUQ6hY7BXnE4/p+rFEOYdYAL66SZn8Tj5ckWdSy\nQ8gT\r\n=seW2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD1hRPhIGF2ABC54DXbCmiZUTCxkHxi15A8hB8gF1EwbQIhAMEDDrqLXG0UpuFmL5I8SIDN0JKIE1XsMxYRIZjLnZ7a"}]},"_npmUser":{"name":"towyuan","email":"towyuan@outlook.com"},"directories":{},"maintainers":[{"name":"towyuan","email":"towyuan@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/a-callback_0.1.1_1630913922166_0.06781646756897075"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-06T07:38:42.166Z","0.1.1":"2021-09-06T07:38:42.297Z","modified":"2022-04-11T12:17:32.587Z"},"maintainers":[{"name":"towyuan","email":"towyuan@outlook.com"}],"description":"An utility to convert node callbacks to promise","keywords":["promise","async","callback","promisify"],"author":{"name":"ty","email":"towyuan@outlook.com"},"license":"MIT","readme":"# a-callback\n\n> A utility to convert node callbacks to promise\n\n## fromCallback\n\n```ts\nfromCallback(\n    resolver: (cb: (error?: any, ...args: any[]) => any) => any,\n    [Object {multiArgs: boolean=false} options]\n) -> Promise\n```\n\n```ts\nfromNode(\n    resolver: (cb: (error?: any, ...args: any[]) => any) => any,\n    [Object {multiArgs: boolean=false} options]\n) -> Promise\n```\n\nReturns a promise that is resolved by a node style callback function. This is the most fitting way to do on the fly\npromisification when libraries don't expose classes for automatic promisification by undefined.\n\nThe resolver function is passed a callback that expects to be called back according to error-first node conventions.\n\nSetting multiArgs to true means the resulting promise will always fulfill with an array of the callback's success\nvalue(s). This is needed because promises only support a single success value while some callback API's have multiple\nsuccess value. The default is to ignore all but the first success value of a callback function.\n\nUsing manual resolver:\n\n```ts\nimport util from 'util';\nimport {fromCallback} from 'a-callback';\n// \"email-templates\" doesn't expose prototypes for promisification\nconst emailTemplates = util.promisify(require('email-templates'));\nconst templatesDir = path.join(__dirname, 'templates');\n\nconst template = await emailTemplates(templatesDir);\nconst [html, text] = await fromCallback(cb => template('newsletter', cb), {multiArgs: true});\nconsole.log(html, text);\n```\n","readmeFilename":"README.md"}