{"name":"try-to-catch","version":"1.0.2","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"function try-catch wrapper for promises","homepage":"http://github.com/coderaiser/try-to-catch","main":"lib/try-to-catch.js","repository":{"type":"git","url":"git://github.com/coderaiser/try-to-catch.git"},"scripts":{"test":"tape 'test/*.js'","watch:test":"nodemon -w lib -w test -x \"npm test\"","lint":"eslint lib test","coverage":"nyc npm test","report":"nyc report --reporter=text-lcov | coveralls","build":"babel lib -d legacy","wisdom":"redrun build legacy","legacy":"echo \"module.exports = require('./try-to-catch')\" > legacy/index.js"},"dependencies":{},"keywords":["try","catch","function","promise","async","await","try-catch","then"],"devDependencies":{"babel-cli":"^6.26.0","babel-preset-env":"^1.6.1","coveralls":"^3.0.0","eslint":"^4.17.0","nodemon":"^1.14.12","nyc":"^11.4.1","redrun":"^5.10.2","tape":"^4.8.0"},"license":"MIT","gitHead":"60bc797a2cbc041c29bf0c0a801f3ce6554e545b","bugs":{"url":"https://github.com/coderaiser/try-to-catch/issues"},"_id":"try-to-catch@1.0.2","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"dist":{"integrity":"sha512-G2EGSGPfCKtkPk/XCpHdcMh1MP//JvcIaFkN7QwcZ2MM7KvP18twf053mfc/gmSZD6ZoNJaRR2HSfGUxUlp5lw==","shasum":"8c9d48f233c4d1679452e9edc8d5e85f653010f1","tarball":"http://registry-npm.ywwl.com/try-to-catch/download/try-to-catch-1.0.2.tgz","fileCount":7,"unpackedSize":5452,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGCg7a65efGSrDvPacOCFxJYNejdt3jgVf0w8Ql3WBiVAiEAsKFd7Ct9v20E2m13c7G2A4U+pC1f6atTDIZBOJ19cxc="}],"size":2624,"noattachment":false,"key":"/try-to-catch/-/try-to-catch-1.0.2.tgz"},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/try-to-catch_1.0.2_1518525881654_0.05874631255927332"},"_hasShrinkwrap":false,"readme":"# Try to Catch [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/try-to-catch.svg?style=flat&longCache=true\n[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/try-to-catch/master.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/try-to-catch \"npm\"\n[BuildStatusURL]: https://travis-ci.org/coderaiser/try-to-catch \"Build Status\"\n[CoverageURL]: https://coveralls.io/github/coderaiser/try-to-catch?branch=master\n[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/try-to-catch/badge.svg?branch=master&service=github\n\nFunctional `try-catch` wrapper for `promises`.\n\n## Install\n\n```\nnpm i try-to-catch\n```\n\n## API\n\n### tryToCatch(fn, [...args])\n\nWrap function to avoid `try-catch` block, resolves `[error, result]`;\n\n### Example\n\nSimplest example with `async-await`:\n\n```js\nconst tryToCatch = require('try-to-catch');\nconst reject = Promise.reject.bind(Promise);\nawait tryToCatch(reject, 'hi');\n// returns\n// [ Error: hi]\n```\n\nCan be used with functions:\n\n```js\nconst tryToCatch = require('try-to-catch');\nawait tryToCatch(() => 5);\n// returns\n[null, 5];\n```\n\nAdvanced example:\n\n```js\nconst {readFile, readdir} = require('fs/promises');\nconst tryToCatch = require('try-to-catch');\n\nread(process.argv[2])\n    .then(console.log)\n    .catch(console.error);\n\nasync function read(path) {\n    const [error, data] = await tryToCatch(readFile, path, 'utf8');\n    \n    if (!error)\n        return data;\n    \n    if (error.code !== 'EISDIR')\n        return error;\n    \n    return await readdir(path);\n}\n```\n\n## Related\n\n- [try-catch](https://github.com/coderaiser/try-catch \"try-catch\") - functional try-catch wrapper.\n\n## License\n\nMIT\n","publish_time":1518525882370,"_cnpm_publish_time":1518525882370,"dist-tags":{"latest":"4.1.0"}}