{"id":50182044,"url":"https://github.com/jaydenfyi/tinyresult","last_synced_at":"2026-05-25T07:05:13.312Z","repository":{"id":306664674,"uuid":"1026835027","full_name":"jaydenfyi/tinyresult","owner":"jaydenfyi","description":"A tiny, zero-dependency library for handling synchronous and asynchronous results with robust error handling","archived":false,"fork":false,"pushed_at":"2025-08-16T16:59:06.000Z","size":215,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-23T06:39:18.852Z","etag":null,"topics":["algebraic-data-types","either","fp","functional-programming","result","result-type"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@jaydenfyi/tinyresult","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaydenfyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-26T17:59:00.000Z","updated_at":"2025-07-27T20:10:41.000Z","dependencies_parsed_at":"2025-07-27T00:30:10.531Z","dependency_job_id":null,"html_url":"https://github.com/jaydenfyi/tinyresult","commit_stats":null,"previous_names":["jaydenfyi/tinyresult"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jaydenfyi/tinyresult","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenfyi%2Ftinyresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenfyi%2Ftinyresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenfyi%2Ftinyresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenfyi%2Ftinyresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaydenfyi","download_url":"https://codeload.github.com/jaydenfyi/tinyresult/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydenfyi%2Ftinyresult/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33464014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T06:32:55.349Z","status":"ssl_error","status_checked_at":"2026-05-25T06:32:35.322Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algebraic-data-types","either","fp","functional-programming","result","result-type"],"created_at":"2026-05-25T07:04:43.051Z","updated_at":"2026-05-25T07:05:13.306Z","avatar_url":"https://github.com/jaydenfyi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e🔀 tinyresult\u003c/h1\u003e\n\nA tiny, zero-dependency library for handling synchronous and asynchronous results with robust error handling.\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"http://npmjs.com/package/@jaydenfyi/tinyresult\"\u003e\u003cimg alt=\"📦 npm version\" src=\"https://img.shields.io/npm/v/@jaydenfyi/tinyresult?color=21bb42\u0026label=%F0%9F%93%A6%20npm\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/jaydenfyi/tinyresult/blob/main/LICENSE.md\" target=\"_blank\"\u003e\u003cimg alt=\"📝 License: MIT\" src=\"https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg\"\u003e\u003c/a\u003e\n\t\u003cimg alt=\"💪 TypeScript: Strict\" src=\"https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg\" /\u003e\n  \u003cimg src=\"https://img.shields.io/bundlejs/size/%40jaydenfyi%2Ftinyresult\"/\u003e\n\u003c/p\u003e\n\n---\n\n## Key Features\n\n- 🛡️ **Type-Safe**: Makes errors first‑class values in the type system - `Result\u003cT, E\u003e` infers and bubbles up both `T` and `E`, letting you chain and handle failures without throwing.\n- 🔄 **Seamless Sync/Async Context Boundaries**: Provides `Result` for synchronous operations and `AsyncResult` for promise-based workflows, with seamless interoperability between them via chaining API methods.\n- 🛠️ **Familiar, Fluent \u0026 Immutable API**: Inspired by ECMAScript built‑ins - use chainable methods like `map`, `flatMap`, `catch` and `finally` to compose workflows cleanly.\n- 📦 **Zero-Dependency**: Lightweight with no external dependencies.\n\n---\n\n## Installation\n\n```shell\nnpm install @jaydenfyi/tinyresult\n```\n\n## Getting Started\n\n`tinyresult` provides a straightforward way to manage operations that can either succeed or fail. Here's a more comprehensive example that showcases chaining and asynchronous operations.\n\n```typescript\nimport { Result, AsyncResult } from \"@jaydenfyi/tinyresult\";\nimport { Octokit } from \"@octokit/rest\";\n\nclass ValidationError {\n  readonly _tag = \"ValidationError\";\n  constructor(readonly message: string) {}\n}\n\nclass NetworkError {\n  readonly _tag = \"NetworkError\";\n  constructor(readonly status: number, readonly message: string) {}\n}\n\nclass UserNotFoundError {\n  readonly _tag = \"UserNotFoundError\";\n  constructor(readonly username: string) {}\n}\n\nconst octokit = new Octokit();\n\nfunction getGithubUserBio(username: string) {\n  return (\n    // Step 1: Start with a synchronous value\n    Result.ok(username)\n      // Step 2: Validate the input\n      .flatMap((u) =\u003e\n        !u || u.trim().length === 0\n          ? Result.error(new ValidationError(\"Username cannot be empty\"))\n          : Result.ok(u),\n      )\n      // Step 3: Log the valid input (side-effect)\n      .tap((u) =\u003e console.log(`Fetching bio for ${u}...`))\n      // Step 4: Switch to an async context to fetch data\n      .flatMap((u) =\u003e\n        AsyncResult.fromPromise(\n          octokit.users.getByUsername({ username: u }),\n          (err) =\u003e new NetworkError(500, err.message),\n        ),\n      )\n      // Step 5: Check the response and extract the data\n      .flatMap((response) =\u003e\n        response.status !== 200\n          ? Result.error(new NetworkError(response.status, \"Failed to fetch user\"))\n          : Result.ok(response.data),\n      )\n      // Step 6: Process the data\n      .flatMap((user) =\u003e\n        !user.bio\n          ? Result.error(new UserNotFoundError(user.login))\n          : Result.ok({ bio: user.bio, login: user.login }),\n      )\n      // Step 7: Transform the success value\n      .map(({ bio, login }) =\u003e ({\n        bio,\n        bioLength: bio.length,\n        user: login,\n      }))\n      // Step 8: Log any errors that occurred in the chain\n      .tapError((err) =\u003e console.error(`[Error Log]: ${err._tag}`))\n  );\n}\n\nasync function run() {\n  const result = await getGithubUserBio(\"jaydenfyi\");\n\n  result.match(\n    (data) =\u003e console.log(\"User Bio details:\", data),\n    (error) =\u003e {\n      switch (error._tag) {\n        case \"ValidationError\":\n          console.error(\"Validation failed:\", error.message);\n          break;\n        case \"NetworkError\":\n          console.error(`Network error (${error.status}):`, error.message);\n          break;\n        case \"UserNotFoundError\":\n          console.error(`Could not find a bio for user: ${error.username}`);\n          break;\n      }\n    },\n  );\n}\n\nrun();\n```\n\n---\n\n## API Reference\n\n### `Result`\n\nHandles synchronous operations.\n\n#### Static Methods\n\n- **`Result.ok\u003cT\u003e(value: T)`**: Creates a success result.\n- **`Result.error\u003cE\u003e(error: E)`**: Creates a failure result.\n- **`Result.try\u003cT, E\u003e(fn: () =\u003e T)`**: Executes a function and catches any thrown error, returning a `Result`.\n- **`Result.all\u003cT, E\u003e(iterable)`**: Transforms an iterable of `Result`s into a single `Result` of an array of values. If any result is an error, the first error is returned.\n- **`Result.from\u003cT, E\u003e(resultLike)`**: Creates a `Result` from a `ResultLike` object (`{ ok: boolean, ... }`).\n- **`Result.isResult(value)`**: Checks if a value is a `Result` instance.\n\n#### Instance Methods\n\n- **`.map\u003cU\u003e(fn)`**: Maps a `Result\u003cT, E\u003e` to `Result\u003cU, E\u003e` by applying a function to a success value.\n- **`.flatMap\u003cU, F\u003e(fn)`**: Maps a `Result\u003cT, E\u003e` to `Result\u003cU, F\u003e` by applying a function that returns a `Result`.\n- **`.mapError\u003cF\u003e(fn)`**: Maps a `Result\u003cT, E\u003e` to `Result\u003cT, F\u003e` by applying a function to a failure value.\n- **`.flatMapError\u003cU, F\u003e(fn)`**: Maps a `Result\u003cT, E\u003e` to `Result\u003cU, F\u003e` by applying a function that returns a `Result`.\n- **`.catch\u003cU\u003e(fn)`**: Recovers from an error by applying a function that returns a new success value.\n- **`.tap(fn)`**: Performs a side-effect with the success value without changing the `Result`.\n- **`.tapError(fn)`**: Performs a side-effect with the error value without changing the `Result`.\n- **`.finally(fn)`**: Performs a side-effect regardless of success or failure.\n- **`.match(onOk, onError)`**: Unwraps the `Result`, executing `onOk` for success or `onError` for failure.\n\n### `AsyncResult`\n\nA promise-like structure for asynchronous operations that resolves to a `Result`.\n\n#### Static Methods\n\n- **`AsyncResult.ok\u003cT\u003e(value: T)`**: Creates an `AsyncResult` that resolves to a success.\n- **`AsyncResult.error\u003cE\u003e(error: E)`**: Creates an `AsyncResult` that resolves to a failure.\n- **`AsyncResult.try\u003cT, E\u003e(fn: () =\u003e T | Promise\u003cT\u003e)`**: Executes an async function and catches any thrown error.\n- **`AsyncResult.all\u003cT, E\u003e(iterable)`**: Similar to `Result.all` but for `AsyncResult`s.\n- **`AsyncResult.from\u003cT, E\u003e(resultLike)`**: Creates an `AsyncResult` from a `ResultLike` or a `Promise\u003cResultLike\u003e`.\n- **`AsyncResult.fromPromise\u003cT, E\u003e(promise)`**: Creates an `AsyncResult` from a `Promise`.\n- **`AsyncResult.isAsyncResult(value)`**: Checks if a value is an `AsyncResult` instance.\n\n#### Instance Methods\n\n`AsyncResult` has the same chainable methods as `Result` (`map`, `flatMap`, etc.), but they operate on the promised `Result` and can accept async callbacks.\n\n- **`.then()`**: `AsyncResult` is \"thenable\" and can be awaited directly in async functions.\n- **`.match(onOk, onError)`**: Returns a `Promise` that resolves with the result of `onOk` or `onError`.\n\n## Prior Art \u0026 Inspiration\n\n- [neverthrow](https://github.com/supermacro/neverthrow)\n- [ECMAScript Try Operator Proposal](https://github.com/arthurfiorette/proposal-try-operator)\n- [Effect.ts](https://github.com/Effect-TS/effect)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydenfyi%2Ftinyresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaydenfyi%2Ftinyresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydenfyi%2Ftinyresult/lists"}