{"name":"try-to-catch","version":"4.1.0","type":"module","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","exports":{".":"./lib/try-to-catch.js"},"repository":{"type":"git","url":"git+https://github.com/coderaiser/try-to-catch.git"},"scripts":{"wisdom":"madrun wisdom","test":"madrun test","test:dts":"madrun test:dts","watch:test":"madrun watch:test","watcher":"madrun watcher","lint":"madrun lint","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report"},"dependencies":{},"keywords":["try","catch","function","promise","async","await","try-catch","then"],"devDependencies":{"check-dts":"^1.0.0","eslint":"^10.0.0","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^31.2.0","madrun":"^13.0.3","nodemon":"^3.1.11","putout":"^42.8.0","superc8":"^12.7.0","supertape":"^13.4.1"},"engines":{"node":">=22"},"license":"MIT","_id":"try-to-catch@4.1.0","gitHead":"5dbf4711836b6a1034dcfb87e20c3d3f254d2528","types":"./lib/try-to-catch.d.ts","bugs":{"url":"https://github.com/coderaiser/try-to-catch/issues"},"_nodeVersion":"26.5.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-phAezhZqLgHHTpbZYe2GgmKe8itTgEX3gfd+YeIsmllgOOpXCDPn1DkDzVWj0mGQPriJgD6AagoUEcX+M2RlGw==","shasum":"a9084485e014de0aa6a769450a514aaec969a424","tarball":"http://registry-npm.ywwl.com/try-to-catch/download/try-to-catch-4.1.0.tgz","fileCount":7,"unpackedSize":6976,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIG/EfbiJwdGyQMSbEoZlQ2VsJTV6BxiDjyrjWAcgOcs7AiAsTQqlhRkl6OXYbHzm+s2qJ7RPXJCOIvZhhLGoSFrZMg=="}],"size":3140,"noattachment":false,"key":"/try-to-catch/-/try-to-catch-4.1.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/try-to-catch_4.1.0_1783772466482_0.8271922305820198"},"_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[NPMURL]: https://npmjs.org/package/try-to-catch \"npm\"\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[BuildStatusURL]: https://github.com/coderaiser/try-to-catch/actions?query=workflow%3A%22Node+CI%22 \"Build Status\"\n[BuildStatusIMGURL]: https://github.com/coderaiser/try-to-catch/workflows/Node%20CI/badge.svg\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\nimport {tryToCatch} from 'try-to-catch';\n\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\nimport {tryToCatch} from 'try-to-catch';\n\nawait tryToCatch(() => 5);\n// returns\n[null, 5];\n```\n\nAdvanced example:\n\n```js\nimport {readFile, readdir} from 'node:fs/promises';\nimport {tryToCatch} from 'try-to-catch';\n\nconst [error, data] = await tryToCatch(read, process.argv[2]);\n\nif (error) {\n    console.error(error);\n    process.exit(1);\n}\n\nconsole.log(data);\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":1783772466629,"_cnpm_publish_time":1783772466629,"dist-tags":{"latest":"4.1.0"}}