{"_id":"@aligheisar/try-catch","_rev":"4-54e666fc43e053245d2241b9aefbf73d","name":"@aligheisar/try-catch","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"@aligheisar/try-catch","version":"0.1.1","keywords":["promise","error-handling","async","try-catch","error","api","typescript","javascript","utilities"],"author":{"url":"https://github.com/aligheisar","name":"Ali Gheisar","email":"ali.gheisar.dev@gmail.com"},"license":"ISC","_id":"@aligheisar/try-catch@0.1.1","maintainers":[{"name":"aligheisar","email":"ali.gheisar.dev@gmail.com"}],"homepage":"https://github.com/aligheisar/try-catch","bugs":{"url":"https://github.com/aligheisar/try-catch/issues"},"dist":{"shasum":"3c1a073fdbc0bb627d542b5cfeaeab215dd146dc","tarball":"https://registry.npmjs.org/@aligheisar/try-catch/-/try-catch-0.1.1.tgz","fileCount":9,"integrity":"sha512-+xW7i65FqnfZKhhzbk2SxroaYtoWUwpj3Rq4v3Dt5oGgk1vR5yZVW6/8xeRh0yMOOegWQx5lj24JXtePxM1JQA==","signatures":[{"sig":"MEUCIFmr5gybYJXbScnpjCpoz1v4Sj16hlyPMZFgQ1qE/EckAiEAkudtRiPAUABBcNokjqKzN7zbZ96D2+C+JZZRNew4orU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4631},"main":"./dist/index.cjs","type":"module","_from":"file:aligheisar-try-catch-0.1.1.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"dev":"tsup --watch","lint":"biome lint","build":"tsup","check":"biome check","format":"biome format --write","lint:fix":"biome lint --write","check:fix":"biome check --write","lint-staged":"lint-staged"},"_npmUser":{"name":"aligheisar","email":"ali.gheisar.dev@gmail.com"},"_resolved":"/tmp/c0f6fbe745242066eedd3605c0165385/aligheisar-try-catch-0.1.1.tgz","_integrity":"sha512-+xW7i65FqnfZKhhzbk2SxroaYtoWUwpj3Rq4v3Dt5oGgk1vR5yZVW6/8xeRh0yMOOegWQx5lj24JXtePxM1JQA==","repository":{"url":"git+https://github.com/aligheisar/try-catch.git","type":"git"},"_npmVersion":"11.5.1","description":"A lightweight TypeScript utility to handle async Promises with typed try/catch results.","directories":{},"sideEffects":false,"_nodeVersion":"24.6.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","husky":"^9.1.7","typescript":"^5.9.3","lint-staged":"^16.2.7","@biomejs/biome":"^2.3.13"},"_npmOperationalInternal":{"tmp":"tmp/try-catch_0.1.1_1769678313664_0.8826163782641343","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@aligheisar/try-catch","version":"0.1.2","description":"A lightweight TypeScript utility to handle async Promises with typed try/catch results.","author":{"name":"Ali Gheisar","email":"ali.gheisar.dev@gmail.com","url":"https://github.com/aligheisar"},"repository":{"type":"git","url":"git+https://github.com/aligheisar/try-catch.git"},"homepage":"https://github.com/aligheisar/try-catch","keywords":["promise","error-handling","async","try-catch","error","api","typescript","javascript","utilities"],"license":"ISC","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","require":"./dist/index.cjs"}},"sideEffects":false,"devDependencies":{"@biomejs/biome":"^2.3.13","husky":"^9.1.7","lint-staged":"^16.2.7","tsup":"^8.5.1","typescript":"^5.9.3"},"scripts":{"build":"tsup","dev":"tsup --watch","lint":"biome lint","lint:fix":"biome lint --write","check":"biome check","check:fix":"biome check --write","format":"biome format --write","lint-staged":"lint-staged"},"_id":"@aligheisar/try-catch@0.1.2","bugs":{"url":"https://github.com/aligheisar/try-catch/issues"},"_integrity":"sha512-Jnm0SvbkKx9wczONayGOfgROChTWm25CQwAAtKh9X8dpBWpGV8SIS3O23ltOyhNCoQz4dJ91fJ7M6leP1IbSwA==","_resolved":"/tmp/c34739de44b2dc3a9b44b10ec0946e8c/aligheisar-try-catch-0.1.2.tgz","_from":"file:aligheisar-try-catch-0.1.2.tgz","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-Jnm0SvbkKx9wczONayGOfgROChTWm25CQwAAtKh9X8dpBWpGV8SIS3O23ltOyhNCoQz4dJ91fJ7M6leP1IbSwA==","shasum":"93ad6506579a21b5279d5a4ac045f34b645f6669","tarball":"https://registry.npmjs.org/@aligheisar/try-catch/-/try-catch-0.1.2.tgz","fileCount":9,"unpackedSize":6180,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAMQOrdLlDs/ZO2inx3A5vh4pnFIXBjvW3tW/x8Ju+wBAiEAtjEr8jh60Q8A9AS00Perb7PLD4j1+R4fQcu1h1xjWEg="}]},"_npmUser":{"name":"aligheisar","email":"ali.gheisar.dev@gmail.com"},"directories":{},"maintainers":[{"name":"aligheisar","email":"ali.gheisar.dev@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/try-catch_0.1.2_1769758928519_0.46750022584620843"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-29T09:18:33.550Z","modified":"2026-01-30T07:42:08.759Z","0.1.0":"2026-01-29T09:14:03.752Z","0.1.1":"2026-01-29T09:18:33.806Z","0.1.2":"2026-01-30T07:42:08.648Z"},"bugs":{"url":"https://github.com/aligheisar/try-catch/issues"},"author":{"name":"Ali Gheisar","email":"ali.gheisar.dev@gmail.com","url":"https://github.com/aligheisar"},"license":"ISC","homepage":"https://github.com/aligheisar/try-catch","keywords":["promise","error-handling","async","try-catch","error","api","typescript","javascript","utilities"],"repository":{"type":"git","url":"git+https://github.com/aligheisar/try-catch.git"},"description":"A lightweight TypeScript utility to handle async Promises with typed try/catch results.","maintainers":[{"name":"aligheisar","email":"ali.gheisar.dev@gmail.com"}],"readme":"# @aligheisar/try-catch\n\nA tiny utility for handling async errors without `try/catch` blocks.\n\nThis package wraps a promise and returns a typed, predictable result object instead of throwing, making error handling easier and more explicit.\n\n## Installation\n\n```bash\nnpm install @aligheisar/try-catch\n```\n\nor\n\n```bash\npnpm add @aligheisar/try-catch\n```\n\nor\n\n```bash\nyarn add @aligheisar/try-catch\n```\n\n## The idea\n\nJavaScript promises throw errors.\nThis utility turns that behavior into data.\n\nInstead of:\n\n```ts\ntry {\n  const data = await doSomething();\n} catch (err) {\n  // handle error\n}\n```\n\nYou get:\n\n```ts\nconst result = await tryCatch(doSomething());\n```\n\n…and handle success and failure explicitly.\n\n## API\n\n### tryCatch\n\n```ts\ntype TryCatchResult<T, E> =\n  | { success: true; data: T }\n  | { success: false; error: E };\n\nfunction tryCatch<T, E = unknown>(\n  promise: Promise<T>\n): Promise<TryCatchResult<T, E>>;\n```\n\n## Basic usage\n\n```ts\nimport { tryCatch } from \"@aligheisar/try-catch\";\n\nconst result = await tryCatch(fetch(\"/api/user\"));\n\nif (result.success) {\n  console.log(result.data);\n} else {\n  console.error(result.error);\n}\n```\n\n## With typed errors\n\n```ts\ntype ApiError = {\n  message: string;\n  code: number;\n};\n\nconst result = await tryCatch<Response, ApiError>(\n  fetch(\"/api/user\")\n);\n\nif (!result.success) {\n  console.error(result.error.code);\n}\n```\n\n## Why use this?\n\n* No `try/catch` nesting\n* Explicit success and failure paths\n* Works well with functional or result-based patterns\n* Fully typed and predictable\n* Zero dependencies\n","readmeFilename":"README.md"}