{"name":"thenify","description":"Promisify a callback-based function","version":"3.1.0","author":{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"},"license":"MIT","repository":{"type":"git","url":"https://github.com/thenables/thenify"},"dependencies":{"native-or-bluebird":"1"},"devDependencies":{"bluebird":"2","istanbul":"0","mocha":"2"},"scripts":{"test":"mocha --reporter spec","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot","test-travis":"istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"},"keywords":["promisify","promise","thenify","then","es6"],"files":["index.js"],"gitHead":"4c093c3583662f20f3342d59f73d61bb96f7d826","bugs":{"url":"https://github.com/thenables/thenify/issues"},"homepage":"https://github.com/thenables/thenify","_id":"thenify@3.1.0","_shasum":"c27cbbc62b7c287edf1a1a3d5cc8426d8aed49f0","_from":".","_npmVersion":"2.1.12","_nodeVersion":"0.11.14","_npmUser":{"name":"dead_horse","email":"dead_horse@qq.com"},"maintainers":[{"name":"jongleberry","email":"jonathanrichardong@gmail.com"},{"name":"dead-horse","email":"dead_horse@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"}],"dist":{"shasum":"c27cbbc62b7c287edf1a1a3d5cc8426d8aed49f0","tarball":"http://registry-npm.ywwl.com/thenify/download/thenify-3.1.0.tgz","integrity":"sha512-0ngb6mLUzolJyQry/KzJ8+u19Ak/MfLfODhyJVR/GFiobY9oqfiCdiyHh77RnxRmi5f+oYVPKc2UDCtkD/ip+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBFi8gjpRpr3QX5qu7/nTDw2m+Km3xVg9BgUcV2Ow4rVAiAYBKJ9gXczKMg7JcXyCRJRPwFsezXNwxkcw7R36NYlJg=="}],"size":2461,"noattachment":false,"key":"/thenify/-/thenify-3.1.0.tgz"},"directories":{},"readme":"\n# thenify\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\nPromisify a callback-based function using [`any-promise`](https://github.com/kevinbeaty/any-promise).\n\n- Preserves function names\n- Uses a native promise implementation if available and tries to fall back to a promise implementation such as `bluebird`\n- Converts multiple arguments from the callback into an `Array`, also support change the behavior by `options.multiArgs`\n- Resulting function never deoptimizes\n- Supports both callback and promise style\n\nAn added benefit is that `throw`n errors in that async function will be caught by the promise!\n\n## API\n\n### fn = thenify(fn, options)\n\nPromisifies a function.\n\n### Options\n\n`options` are optional.\n\n- `options.withCallback` - support both callback and promise style, default to `false`.\n- `options.multiArgs` - change the behavior when callback have multiple arguments. default to `true`.\n  - `true` - converts multiple arguments to an array\n  - `false`- always use the first argument\n  - `Array` - converts multiple arguments to an object with keys provided in `options.multiArgs`\n\n- Turn async functions into promises\n\n```js\nvar thenify = require('thenify');\n\nvar somethingAsync = thenify(function somethingAsync(a, b, c, callback) {\n  callback(null, a, b, c);\n});\n```\n\n- Backward compatible with callback\n\n```js\nvar thenify = require('thenify');\n\nvar somethingAsync = thenify(function somethingAsync(a, b, c, callback) {\n  callback(null, a, b, c);\n}, { withCallback: true });\n\n// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);\n// somethingAsync(a, b, c, function () {});\n```\n\nor use `thenify.withCallback()`\n\n```js\nvar thenify = require('thenify').withCallback;\n\nvar somethingAsync = thenify(function somethingAsync(a, b, c, callback) {\n  callback(null, a, b, c);\n});\n\n// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);\n// somethingAsync(a, b, c, function () {});\n```\n\n- Always return the first argument in callback\n\n```js\nvar thenify = require('thenify');\n\nvar promise = thenify(function (callback) {\n  callback(null, 1, 2, 3);\n}, { multiArgs: false });\n\n// promise().then(function onFulfilled(value) {\n//   assert.equal(value, 1);\n// });\n```\n\n- Converts callback arguments to an object\n\n```js\nvar thenify = require('thenify');\n\nvar promise = thenify(function (callback) {\n  callback(null, 1, 2, 3);\n}, { multiArgs: [ 'one', 'tow', 'three' ] });\n\n// promise().then(function onFulfilled(value) {\n//   assert.deepEqual(value, {\n//     one: 1,\n//     tow: 2,\n//     three: 3\n//   });\n// });\n```\n\n[gitter-image]: https://badges.gitter.im/thenables/thenify.png\n[gitter-url]: https://gitter.im/thenables/thenify\n[npm-image]: https://img.shields.io/npm/v/thenify.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/thenify\n[github-tag]: http://img.shields.io/github/tag/thenables/thenify.svg?style=flat-square\n[github-url]: https://github.com/thenables/thenify/tags\n[travis-image]: https://img.shields.io/travis/thenables/thenify.svg?style=flat-square\n[travis-url]: https://travis-ci.org/thenables/thenify\n[coveralls-image]: https://img.shields.io/coveralls/thenables/thenify.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/thenables/thenify\n[david-image]: http://img.shields.io/david/thenables/thenify.svg?style=flat-square\n[david-url]: https://david-dm.org/thenables/thenify\n[license-image]: http://img.shields.io/npm/l/thenify.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/thenify.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/thenify\n","publish_time":1420515140600,"_cnpm_publish_time":1420515140600,"dist-tags":{"latest":"3.3.1"}}