{"name":"try-to-catch","version":"4.0.3","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.3","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":"e29ef0c7ffe25c2376e9683e8cd90ebcc8791606","tarball":"http://registry-npm.ywwl.com/try-to-catch/download/try-to-catch-4.0.3.tgz","fileCount":7,"integrity":"sha512-mUz1zpe6nkRQW0XZ/Ojfe/Eg7e5h3s+r+h7ONfP3Oo27/Jm8mkNDAnLzZ/A3sEMApROolzuJGBiQhGmmVDAFLw==","signatures":[{"sig":"MEUCIC3vq8fIA2fjRPeXF99wxgik8I223dWVTfL67TxnJgK6AiEAw3Rgk5O+a4+Mmcb2Rr+mlAcZ+1iJbd44z7y8bF/LnjM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":220467,"size":78991,"noattachment":false,"key":"/try-to-catch/-/try-to-catch-4.0.3.tgz"},"main":"lib/try-to-catch.cjs","type":"module","engines":{"node":">=22"},"exports":{".":{"import":"./lib/try-to-catch.js","require":"./lib/try-to-catch.cjs"}},"gitHead":"f627f7d0af6886a42985d2c4c7004d6fd96b9437","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.2.1","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.3_1767559143614_0.26749739996985933","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":1767559143777,"_cnpm_publish_time":1767559143777,"dist-tags":{"latest":"4.1.0"}}