{"_id":"@chejholloway/result-guard","_rev":"2-76198f627c6ee4aa37795485c5aeeecb","name":"@chejholloway/result-guard","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"@chejholloway/result-guard","version":"0.1.1","keywords":["result","error-handling","neverthrow","typescript","rust"],"license":"MIT","_id":"@chejholloway/result-guard@0.1.1","maintainers":[{"name":"chejholloway","email":"chejholloway@protonmail.com"}],"dist":{"shasum":"481c7db01bde9ebcea54784bdbc9f04559418d95","tarball":"https://registry.npmjs.org/@chejholloway/result-guard/-/result-guard-0.1.1.tgz","fileCount":19,"integrity":"sha512-CsFFdsfbCKQrrcatlrIWilN0X2IeaZoL8lfHKW5KLUnLRjNxhCJECXBMAujuHHWodPrl9sr2D9WjxUyFPdnoFw==","signatures":[{"sig":"MEQCIBsQwsCbc5MojjNE250lWn3bNBpktcBSNUTkYcxfhod7AiBfYyRaqLZ3eRYzhXHJVamPdjoS83iTHgX1h4Bi7eQtMw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18104},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"test":"vitest run","build":"tsc -p tsconfig.json","lint:self":"eslint . --ext .ts,.tsx","typecheck":"tsc -p tsconfig.json --noEmit"},"_npmUser":{"name":"chejholloway","email":"chejholloway@protonmail.com"},"repository":{"url":"git+https://github.com/chejholloway/result-guard.git","type":"git","directory":"packages/core"},"description":"Rust-like Result-based error handling for JS/TS, built on neverthrow. Wraps throwing functions so they return Result/ResultAsync instead, with a decorator for class-based code.","directories":{},"_nodeVersion":"24.18.1","dependencies":{"neverthrow":"^8.1.1"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.4","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/result-guard_0.1.1_1785975448992_0.5954018389684101","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@chejholloway/result-guard","version":"0.1.2","description":"Rust-like Result-based error handling for JS/TS, built on neverthrow. Wraps throwing functions so they return Result/ResultAsync instead, with a decorator for class-based code.","type":"module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/chejholloway/result-guard.git","directory":"packages/core"},"keywords":["result","error-handling","neverthrow","typescript","rust"],"main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"dependencies":{"neverthrow":"^8.1.1"},"devDependencies":{"typescript":"^5.6.3","vitest":"^2.1.4"},"scripts":{"build":"tsc -p tsconfig.json","typecheck":"tsc -p tsconfig.json --noEmit","lint:self":"eslint . --ext .ts,.tsx","test":"vitest run"},"_nodeVersion":"24.18.1","_id":"@chejholloway/result-guard@0.1.2","dist":{"integrity":"sha512-3ezW9W6McFA4WwPSx4Q53HBPyShhmSsHiBsJr/6biBEIsjLRjZ+pW0m/0RRB2hBxHRpdBVL/kLuasQNwXGm+tg==","shasum":"d948672810d8d1acbfa5db426000804fbfd4bc33","tarball":"https://registry.npmjs.org/@chejholloway/result-guard/-/result-guard-0.1.2.tgz","fileCount":19,"unpackedSize":18104,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIADifmhY9//AvoMEhuP4dx0ds0z6dpcPeE3EIA/3EDHZAiBVrv7iYKm2hwmsx3N7M4NIULO0KY5T/EB9SIAoxDv1NA=="}]},"_npmUser":{"name":"chejholloway","email":"chejholloway@protonmail.com"},"directories":{},"maintainers":[{"name":"chejholloway","email":"chejholloway@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/result-guard_0.1.2_1786032064824_0.5136375251911429"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-06T00:17:28.852Z","modified":"2026-08-06T16:01:05.110Z","0.1.1":"2026-08-06T00:17:29.135Z","0.1.2":"2026-08-06T16:01:04.960Z"},"license":"MIT","keywords":["result","error-handling","neverthrow","typescript","rust"],"repository":{"type":"git","url":"git+https://github.com/chejholloway/result-guard.git","directory":"packages/core"},"description":"Rust-like Result-based error handling for JS/TS, built on neverthrow. Wraps throwing functions so they return Result/ResultAsync instead, with a decorator for class-based code.","maintainers":[{"name":"chejholloway","email":"chejholloway@protonmail.com"}],"readme":"# result-guard\n\nWraps a throwing function so it returns a [neverthrow](https://github.com/supermacro/neverthrow) `Result`/`ResultAsync` instead. See the [project README](https://github.com/yourname/result-guard) for the full problem statement and design reasoning.\n\n## Install\n\n```bash\nnpm install result-guard neverthrow\n```\n\n## Usage\n\n```ts\nimport { guard } from \"result-guard\";\n\nasync function fetchUser(id: string) {\n  if (!id) throw new Error(\"missing id\");\n  return { id, name: \"Alice\" };\n}\n\nconst guardedFetch = guard(fetchUser);\n\nconst result = await guardedFetch(\"123\");\nresult.match(\n  (user) => console.log(user),\n  (error) => console.error(error.kind === \"error\" ? error.message : \"unknown failure\")\n);\n```\n\nBy default, `guard()` gives you `Result<T, DefaultGuardError>` — `{ kind: \"error\", name, message, cause }` if the caught value was a real `Error`, or `{ kind: \"unknown\", cause }` otherwise. Pass your own error mapper to fully replace it with typed errors specific to your domain:\n\n```ts\ntype ApiError = { kind: \"not-found\" } | { kind: \"server-error\"; status: number };\n\nconst guardedFetch = guard(fetchUser, (e): ApiError =>\n  e instanceof NotFoundError ? { kind: \"not-found\" } : { kind: \"server-error\", status: 500 }\n);\n```\n\n## Decorator\n\nFor class-based code:\n\n```ts\nclass UserService {\n  @ResultGuard()\n  async fetchUser(id: string) {\n    if (!id) throw new Error(\"missing id\");\n    return { id, name: \"Alice\" };\n  }\n}\n```\n\nSync methods stay synchronous — `guard()` never forces a `Promise` onto a function that wasn't already async.\n\n## License\n\nMIT\n","readmeFilename":""}