{"name":"try-to-catch","version":"4.0.5","keywords":["try","catch","function","promise","async","await","try-catch","then"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"try-to-catch@4.0.5","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"http://github.com/coderaiser/try-to-catch","bugs":{"url":"https://github.com/coderaiser/try-to-catch/issues"},"dist":{"shasum":"98b55c9e46d3155f600683abc2ae658af4b51f56","tarball":"http://registry-npm.ywwl.com/try-to-catch/download/try-to-catch-4.0.5.tgz","fileCount":5,"integrity":"sha512-VKBslDQsy4pGj2TMNgDdskWb7AWSi/9dPEmcNv3sdL0+aRMQTPJo6aEqlcuN0vbOwFfsE1oAXmx3bFdf6vrJFg==","signatures":[{"sig":"MEUCIGgYw6Rg2yTNiH42vQGkW7pWMXH1ldebPR7hdwsdBKo0AiEAyfDAjRiHI3va9aQTBAwHDA+gc9fJp2iP5HwEK/Dgx/w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6183,"size":2800,"noattachment":false,"key":"/try-to-catch/-/try-to-catch-4.0.5.tgz"},"main":"lib/try-to-catch.js","type":"module","engines":{"node":">=22"},"exports":{".":"./lib/try-to-catch.js"},"gitHead":"2597ac75c07506bc937d84609da50b6706c02d98","scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"repository":{"url":"git+https://github.com/coderaiser/try-to-catch.git","type":"git"},"_npmVersion":"11.4.2","description":"function try-catch wrapper for promises","directories":{},"_nodeVersion":"25.5.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","eslint":"^9.39.2","madrun":"^11.0.6","putout":"^41.2.3","nodemon":"^3.1.11","supertape":"^11.5.1","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^29.2.0"},"_npmOperationalInternal":{"tmp":"tmp/try-to-catch_4.0.5_1769891528914_0.257424933352177","host":"s3://npm-registry-packages-npm-production"},"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":1769891529060,"_cnpm_publish_time":1769891529060,"dist-tags":{"latest":"4.1.0"}}