{"_id":"@allynet/ishod","_rev":"5-e169fe0db3f539b3817304318512e17f","name":"@allynet/ishod","dist-tags":{"latest":"1.1.2"},"versions":{"0.0.1":{"name":"@allynet/ishod","version":"0.0.1","author":{"url":"https://allypost.net","name":"Josip Igrec","email":"me@allypost.net"},"license":"MIT","_id":"@allynet/ishod@0.0.1","maintainers":[{"name":"allypost","email":"me@allypost.net"}],"homepage":"https://github.com/allynet/ishod","bugs":{"url":"https://github.com/allynet/ishod/issues"},"dist":{"shasum":"97f86e98be07541ab21558bb7fdc8beb81110eec","tarball":"https://registry.npmjs.org/@allynet/ishod/-/ishod-0.0.1.tgz","fileCount":17,"integrity":"sha512-QLZFjS0UJzM7iPZWIqcH1/yknWyIctkLhPnqfqEJwSlUyFPfGYF+kPuoA3BxjNuiRqOhvv1vCLRZeyZBYYEpUA==","signatures":[{"sig":"MEQCIGBmfvT8swI5PlZlnJU6UUnAE9oTHFmFfIFhs6M14TcGAiBJnRurfGCTdQ+cTQBoiJyYyLdMsEOzVIvGBhE17M+NKQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63279},"main":"dist/index.cjs.js","type":"module","types":"dist/index.d.ts","module":"dist/index.es.js","gitHead":"aa78aaf73629f22ca456a32ec96c40b3b24ed33e","scripts":{"test":"vitest","build":"tsc && vite build","build:docs":"typedoc","test:coverage":"vitest --coverage"},"_npmUser":{"name":"allypost","email":"me@allypost.net"},"repository":{"url":"git+https://github.com/allynet/ishod.git","type":"git"},"_npmVersion":"11.3.0","description":"A simple, yet powerful, result type for TypeScript.","directories":{},"_nodeVersion":"23.9.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^6.2.6","vitest":"^3.1.1","typedoc":"^0.28.2","@types/bun":"^1.2.9","@biomejs/biome":"1.9.4","vite-plugin-dts":"^4.5.3","@vitest/coverage-v8":"3.1.1","typedoc-plugin-markdown":"^4.6.2","@total-typescript/ts-reset":"^0.6.1"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/ishod_0.0.1_1744667731193_0.6727487932215841","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@allynet/ishod","version":"1.0.0","author":{"url":"https://allypost.net","name":"Josip Igrec","email":"me@allypost.net"},"license":"MIT","_id":"@allynet/ishod@1.0.0","maintainers":[{"name":"allypost","email":"me@allypost.net"}],"homepage":"https://allynet.github.io/ishod/","bugs":{"url":"https://github.com/allynet/ishod/issues"},"dist":{"shasum":"8e17f1f687aa288c164f8bdf5e40d1f714ace0d8","tarball":"https://registry.npmjs.org/@allynet/ishod/-/ishod-1.0.0.tgz","fileCount":17,"integrity":"sha512-ubfXGXqCe8Vttnt2xO69brnBJT8dKNZGuWNd/ThJKgh51SDQ7dQk63qVSZnsQC62vvwmtcMQYmjl/xuscJRR7A==","signatures":[{"sig":"MEUCIQCDq8MtLhF9kzOMOh8rzR1OLBQa9qhLf4YFNhx50uKtyAIgDk2+gz93KjfvsWRbOzY28FZjHRtQ6lm34NdHBWjbMrE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":66229},"main":"dist/index.cjs.js","type":"module","types":"dist/index.d.ts","module":"dist/index.es.js","gitHead":"392efc609d5fc0ebacd3dd58ef3eb2b57099cab2","scripts":{"lint":"biome check .","test":"npm run test:watch -- --run","build":"tsc && vite build","lint:fix":"biome check --write .","build:docs":"typedoc","test:watch":"vitest --clearScreen --typecheck","test:coverage":"npm run test -- --coverage"},"_npmUser":{"name":"allypost","email":"me@allypost.net"},"repository":{"url":"git+https://github.com/allynet/ishod.git","type":"git"},"_npmVersion":"10.9.2","description":"A simple, yet powerful, result type for TypeScript.","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^6.2.6","vitest":"^3.1.1","typedoc":"^0.28.2","@types/bun":"^1.2.9","@biomejs/biome":"1.9.4","vite-plugin-dts":"^4.5.3","@vitest/coverage-v8":"3.1.1","typedoc-plugin-markdown":"^4.6.2","@total-typescript/ts-reset":"^0.6.1"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/ishod_1.0.0_1744705708741_0.2537006280536782","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@allynet/ishod","version":"1.0.1","author":{"url":"https://allypost.net","name":"Josip Igrec","email":"me@allypost.net"},"license":"MIT","_id":"@allynet/ishod@1.0.1","maintainers":[{"name":"allypost","email":"me@allypost.net"}],"homepage":"https://allynet.github.io/ishod/","bugs":{"url":"https://github.com/allynet/ishod/issues"},"dist":{"shasum":"5ef690c904443075b885e0322d9a6577ebcf67a7","tarball":"https://registry.npmjs.org/@allynet/ishod/-/ishod-1.0.1.tgz","fileCount":8,"integrity":"sha512-2D4n8keugdcc6V0iKQQQRviv3HOsNp8NYrr7zhCbMpuFvrWpkkoxVsmyChyq5nMa7kAPHkqpfR3yZirSn0hA1g==","signatures":[{"sig":"MEUCIQCmmJODPs9n+I4/el0eAA1/zd+Lo8o/bAZO/Rqe8/J/TAIgfNfP4h2BBBMYjeLEsK4CRvRVKL7LOfuJdLUWNriDJN0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":49923},"main":"dist/index.cjs.js","type":"module","types":"dist/index.d.ts","module":"dist/index.es.js","gitHead":"bc7706eff7c23dcb9b6c8e48ade80976e2ffab9a","scripts":{"lint":"biome check .","test":"npm run test:watch -- --run","build":"tsc && vite build","lint:fix":"biome check --write .","build:docs":"typedoc","test:watch":"vitest --clearScreen --typecheck","test:coverage":"npm run test -- --coverage"},"_npmUser":{"name":"allypost","email":"me@allypost.net"},"repository":{"url":"git+https://github.com/allynet/ishod.git","type":"git"},"_npmVersion":"10.9.2","description":"A simple, yet powerful, result type for TypeScript.","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^6.2.6","vitest":"^3.1.1","typedoc":"^0.28.2","@types/bun":"^1.2.9","@biomejs/biome":"1.9.4","vite-plugin-dts":"^4.5.3","@vitest/coverage-v8":"3.1.1","typedoc-plugin-markdown":"^4.6.2","@total-typescript/ts-reset":"^0.6.1"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/ishod_1.0.1_1744739571057_0.7783867725282514","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@allynet/ishod","version":"1.1.0","author":{"url":"https://allypost.net","name":"Josip Igrec","email":"me@allypost.net"},"license":"MIT","_id":"@allynet/ishod@1.1.0","maintainers":[{"name":"allypost","email":"me@allypost.net"}],"homepage":"https://allynet.github.io/ishod/","bugs":{"url":"https://github.com/allynet/ishod/issues"},"dist":{"shasum":"19184bcd3d4e51332bce0a42cbaa477f0c7030d3","tarball":"https://registry.npmjs.org/@allynet/ishod/-/ishod-1.1.0.tgz","fileCount":8,"integrity":"sha512-WWpBkQCHQ17h/X5Csi27GYYFeKJDfd0sywdwVaH4uGLBFvY9D1qBh4Genj82ZSH4t1hAh1OKP7blxUvg/t42IA==","signatures":[{"sig":"MEUCIQDGreYwPAAFgkpuriXe8CHGs9O0uedvXDFxGGwXnQA8kAIgMagyLOf2z7IcCB9wWUc2mcOZRBl6CLI3tn74F+Rxunw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":73700},"main":"dist/index.cjs.js","type":"module","types":"dist/index.d.ts","module":"dist/index.es.js","gitHead":"4c4b50f8301e2311cd5c6183c5a9e94769ab2b30","scripts":{"lint":"biome check .","test":"npm run test:watch -- --run","build":"tsc && vite build","lint:fix":"biome check --write .","build:docs":"typedoc","test:watch":"vitest --clearScreen --typecheck","test:coverage":"npm run test -- --coverage"},"_npmUser":{"name":"allypost","email":"me@allypost.net"},"repository":{"url":"git+https://github.com/allynet/ishod.git","type":"git"},"_npmVersion":"10.9.2","description":"A simple, yet powerful, result type for TypeScript.","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"vite":"^6.2.6","vitest":"^3.1.1","typedoc":"^0.28.2","@types/bun":"^1.2.9","@biomejs/biome":"1.9.4","vite-plugin-dts":"^4.5.3","@vitest/coverage-v8":"3.1.1","typedoc-plugin-markdown":"^4.6.2","@total-typescript/ts-reset":"^0.6.1"},"peerDependencies":{"typescript":"^5"},"_npmOperationalInternal":{"tmp":"tmp/ishod_1.1.0_1745872381852_0.6760713264625848","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"@allynet/ishod","author":{"name":"Josip Igrec","email":"me@allypost.net","url":"https://allypost.net"},"version":"1.1.2","description":"A simple, yet powerful, result type for TypeScript.","repository":{"type":"git","url":"git+https://github.com/allynet/ishod.git"},"license":"MIT","homepage":"https://allynet.github.io/ishod/","main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","type":"module","scripts":{"build":"tsc && vite build","build:docs":"typedoc","lint":"biome check .","lint:fix":"biome check --write .","test":"npm run test:watch -- --run","test:watch":"vitest --clearScreen --typecheck","test:coverage":"npm run test -- --coverage","test:e2e":"bash e2e/run.sh"},"devDependencies":{"@biomejs/biome":"1.9.4","@total-typescript/ts-reset":"^0.6.1","@types/bun":"^1.2.9","@vitest/coverage-v8":"3.1.1","typedoc":"^0.28.2","typedoc-plugin-markdown":"^4.6.2","vite":"^6.2.6","vite-plugin-dts":"^4.5.3","vitest":"^3.1.1"},"peerDependencies":{"typescript":"^5"},"gitHead":"9ae8532018174a9d9aa02f28a9476fdfeba01425","_id":"@allynet/ishod@1.1.2","bugs":{"url":"https://github.com/allynet/ishod/issues"},"_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-nZUcJgG7pC5d5djD4v3pXRLAzOcrHAkkWBQ4eYujaVNEd2AqL6ygWqQ+u1YaUXM1nSM7UQzA3Kpwg6aTZLc2Gw==","shasum":"5b9a35293fcec5150be0119adf6fff3df9a7096a","tarball":"https://registry.npmjs.org/@allynet/ishod/-/ishod-1.1.2.tgz","fileCount":8,"unpackedSize":73390,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@allynet%2fishod@1.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCcvXuFVrSEbqWmqIebMwd5AtaMBjhMjoRP9eHELV8wcQIhALfD+nDCrQYZq139ql0PTeSwOE7tKyzeroky6Vu0ZGAt"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:85f86402-86fd-465c-82aa-ca78ed884a99"}},"directories":{},"maintainers":[{"name":"allypost","email":"me@allypost.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ishod_1.1.2_1781126984853_0.21960605745533734"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-14T21:55:31.082Z","modified":"2026-06-10T21:29:45.269Z","0.0.1":"2025-04-14T21:55:31.387Z","1.0.0":"2025-04-15T08:28:28.898Z","1.0.1":"2025-04-15T17:52:51.288Z","1.1.0":"2025-04-28T20:33:02.017Z","1.1.2":"2026-06-10T21:29:44.986Z"},"bugs":{"url":"https://github.com/allynet/ishod/issues"},"author":{"name":"Josip Igrec","email":"me@allypost.net","url":"https://allypost.net"},"license":"MIT","homepage":"https://allynet.github.io/ishod/","repository":{"type":"git","url":"git+https://github.com/allynet/ishod.git"},"description":"A simple, yet powerful, result type for TypeScript.","maintainers":[{"name":"allypost","email":"me@allypost.net"}],"readme":"# ishod\n\n`ishod` is a really small (&lt;0.5kb gzipped) and simple utility library for working with promises and results.\n\nIt helps you handle errors uniformly and safely across sync and async code.\n\nThe motivational blog post can be found here: https://josip.igr.ec/blog/building-result-in-typescript/\n\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40allynet%2Fishod)\n<a href=\"https://www.npmjs.com/package/@allynet/ishod\">![NPM Version](https://img.shields.io/npm/v/%40allynet%2Fishod)</a>\n\n## Installation\n\nUsing your package manager of choice:\n\n<details>\n  <summary>npm</summary>\n\n```bash\nnpm install @allynet/ishod\n```\n\n</details>\n\n<details>\n  <summary>yarn</summary>\n\n```bash\nyarn add @allynet/ishod\n```\n\n</details>\n\n<details>\n  <summary>pnpm</summary>\n\n```bash\npnpm install @allynet/ishod\n```\n\n</details>\n\n<details>\n  <summary>bun</summary>\n\n```bash\nbun install @allynet/ishod\n```\n\n</details>\n\n## Examples\n\n<details>\n<summary>\n\n### Logging errors\n\nwithout having to try/catch all the time and leave a bunch of `let val = null` variables around\n\n</summary>\n\n```ts\nimport { $result } from \"@allynet/ishod\";\n\n// Do an unsafe operation safely\nconst gamble = $result.try$(() => {\n  if (Math.random() > 0.5) {\n    return 5;\n  }\n\n  throw new Error(\"error\");\n});\n\n// And process the result safely\nconst doubled = $result.map(gamble, (x) => x * 2);\n\n// Or log the error if it happens\n$result.tapErr(gamble, (error) => {\n  console.error(error);\n});\n\n// without having to check everything yourself\n// or creating a bunch of `let val = null` variables\n```\n\n</details>\n\n<details>\n<summary>\n\n### Error handling\n\nuniformly with promises and sync code\n\n</summary>\n\n```ts\nimport { $result } from \"@allynet/ishod\";\n\nconst requestJson = (url: string) =>\n  $result\n    .try$(fetch(url))\n    .then((x) => $result.map(x, (res) => res.json()))\n    .then((x) => $result.tapErr(x, (error) => console.error(error)));\n\nconst response = await requestJson(\"https://api.example.com/data\");\n\nif ($result.isOk(response)) {\n  const data = $result.unwrap(response);\n  console.log(`Got the response data right here: ${data}`);\n}\n```\n\n</details>\n\n<details>\n<summary>\n\n### Returning informative results\n\ninstead of just doing `MyThing | null` for everything and praying for the best\n\n</summary>\n\n```ts\nimport { $result } from \"@allynet/ishod\";\n\nconst divide = (a: number, b: number) => {\n  if (b === 0) {\n    return $result.err(\"division by zero\");\n  }\n\n  if (a === b) {\n    return $result.err(\"division by itself\");\n  }\n\n  return $result.ok(a / b);\n};\n\nconst result = divide(1, 0);\n//    ^? Result<number, \"division by zero\" | \"division by itself\">\n\nconst resultDoubled = $result.map(result, (x) => x * 2);\n//    ^? Result<number, \"division by zero\" | \"division by itself\">\n```\n\n</details>\n\n## Docs overview\n\nThe full documentation is available at <https://allynet.github.io/ishod/>.\n\nThe following is a quick overview of the API.\n\n### Result\n\nishod provides a `Result` type that can be used to represent the result of an operation.\n\nIt boils down to the following:\n\n```ts\ntype Result<T, E> = Ok<T> | Err<E>;\n\ntype Ok<T> = { ok: true; data: T };\ntype Err<E> = { ok: false; error: E };\n```\n\nYou can use the `ok` and `err` functions to create results:\n\n```ts\nconst result: Ok<number> = ok(1);\n```\n\n```ts\nconst result: Err<string> = err(\"error\");\n```\n\nYou can use the `isOk` and `isErr` functions to check the type of a result:\n\n```ts\nconst isOkOk: true = isOk(ok(1));\nconst isErrOk: false = isErr(ok(1));\nconst isErrErr: true = isErr(err(\"error\"));\nconst isOkErr: false = isOk(err(\"error\"));\n```\n\nIf you need to get the value from the result, you can use the `unwrap` function:\n\n```ts\nconst data = unwrap(ok(1));\nassert.equal(data, 1);\n```\n\nIf you need to get the error from the result, you can use the `unwrapErr` function:\n\n```ts\nconst error = unwrapErr(err(\"error\"));\nassert.equal(error, \"error\");\n```\n\nYou can use the `unwrapForced` function to force get the data from the result.\nIt will return the data on OK results, and on Err results it will return undefined.\n\n```ts\nconst data = unwrapForced(ok(1));\nassert.equal(data, 1);\n\nconst otherData = unwrapForced(err(\"error\"));\nassert.equal(otherData, undefined); // !!\n```\n\nYou can use the `unwrapOr` function to get the value of a result or a default value:\n\n```ts\nconst data = unwrapOr(ok(1), 0);\nassert.equal(data, 1);\n\nconst otherData = unwrapOr(err(\"error\"), 0);\nassert.equal(otherData, 0);\n```\n\n### Tapping\n\nYou can use the `tap` function to run a function on a result if it's ok:\n\n```ts\nconst result = ok(1);\nconst data = tap(result, (data) => {\n  console.log(data);\n});\nassert.ok(data === result);\n```\n\nThe `tap` function won't modify the result.\n\nYou can use the `tapErr` function to run a function on an error:\n\n```ts\nconst result = err(\"error\");\nconst error = tapErr(result, (error) => {\n  console.log(error);\n});\nassert.ok(error === result);\n```\n\nThe `tapErr` function won't modify the result.\n\n### Mapping\n\nYou can use the `map` function to map a result value:\n\n```ts\nconst result = ok(1);\nconst data = map(result, (data) => data * 2);\nassert.deepEqual(data, ok(2));\n```\n\nYou can use the `mapErr` function to map an error:\n\n```ts\nconst result = err(\"error\");\nconst error = mapErr(result, (error) => error.toUpperCase());\nassert.deepEqual(error, err(\"ERROR\"));\n```\n","readmeFilename":"README.md"}