{"id":17929154,"url":"https://github.com/skarab42/result","last_synced_at":"2025-07-24T23:05:50.652Z","repository":{"id":216806640,"uuid":"742494450","full_name":"skarab42/result","owner":"skarab42","description":"Provides a robust and type-safe way to handle success and failure outcomes in TypeScript, utilizing symbolic indexing for clear result differentiation.","archived":false,"fork":false,"pushed_at":"2024-04-03T17:34:04.000Z","size":124,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-08T21:52:46.503Z","etag":null,"topics":["error-handling","functional-programming","typescript"],"latest_commit_sha":null,"homepage":"","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/skarab42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"skarab42"}},"created_at":"2024-01-12T15:52:39.000Z","updated_at":"2024-01-15T07:02:55.000Z","dependencies_parsed_at":"2024-01-13T00:40:28.992Z","dependency_job_id":"5992a9b2-d370-4eaa-af01-026b6eaa16da","html_url":"https://github.com/skarab42/result","commit_stats":null,"previous_names":["skarab42/result"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/skarab42/result","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skarab42%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skarab42%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skarab42%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skarab42%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skarab42","download_url":"https://codeload.github.com/skarab42/result/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skarab42%2Fresult/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264728454,"owners_count":23654800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["error-handling","functional-programming","typescript"],"created_at":"2024-10-28T21:07:50.613Z","updated_at":"2025-07-24T23:05:50.490Z","avatar_url":"https://github.com/skarab42.png","language":"TypeScript","funding_links":["https://github.com/sponsors/skarab42"],"categories":[],"sub_categories":[],"readme":"# @skarab/result\n\n`@skarab/result` is a TypeScript library providing a robust pattern for handling success and failure outcomes in a functional programming style. Utilizing advanced TypeScript features, it allows developers to create expressive, type-safe APIs that clearly distinguish between successful results and errors.\n\n## Features\n\n- **Type-Safe Success and Failure Handling:** Clearly differentiate between success and failure cases using TypeScript types.\n- **Functional Approach:** Embrace a functional programming style for handling results.\n- **Easy to Use:** Simple API with powerful type inference.\n\n## Installation\n\nTo install the package, use pnpm, npm or yarn:\n\n## Installation\n\n```bash\npnpm add @skarab/result\n```\n\n## Usage\n\nHere's a basic example of how to use `@skarab/result`:\n\n```ts\nimport { success, failure, isSuccess, unwrap } from '@skarab/result';\n\nfunction performOperation(): Result\u003cnumber, Error\u003e {\n  // some operation\n  if (/* operation successful */) {\n    return success(42);\n  } else {\n    return failure(new Error('Operation failed'));\n  }\n}\n\nconst result = performOperation();\n\nif (isSuccess(result)) {\n  console.log('Success with value:', unwrap(result));\n} else {\n  console.log('Failure with error:', unwrap(result));\n}\n```\n\n## API Documentation\n\n### Types\n\n#### `Success\u003cSuccessValue\u003e`\n\n- A type representing a successful result.\n- Contains a value of type `SuccessValue`.\n- Indexed by a unique success symbol, ensuring type safety and avoiding property clashes.\n\n#### `Failure\u003cFailureValue\u003e`\n\n- A type representing a failure result.\n- Contains a value of type `FailureValue`.\n- Indexed by a unique failure symbol, providing clear differentiation from the `Success` type.\n\n#### `Result\u003cSuccessValue, FailureValue\u003e`\n\n- A union type representing either a success or a failure.\n- Encapsulates `Success\u003cSuccessValue\u003e` and `Failure\u003cFailureValue\u003e`.\n\n### Functions\n\n#### `success\u003cSuccessValue\u003e(value: SuccessValue): Success\u003cSuccessValue\u003e`\n\n- Creates a success result containing the provided value.\n- Useful for wrapping successful outcomes in a type-safe manner.\n- **Parameters:**\n  - `value`: The value to be associated with the success.\n\n#### `failure\u003cFailureValue\u003e(value: FailureValue): Failure\u003cFailureValue\u003e`\n\n- Creates a failure result containing the provided value.\n- Ideal for expressing error states or unsuccessful outcomes.\n- **Parameters:**\n  - `value`: The value to be associated with the failure.\n\n#### `isSuccess\u003cSuccessValue\u003e(result: Result\u003cSuccessValue, unknown\u003e): result is Success\u003cSuccessValue\u003e`\n\n- A type guard function that checks if a given result is a success.\n- Returns `true` if the result is a success, otherwise `false`.\n- Helps in narrowing down the type of the result to `Success\u003cSuccessValue\u003e` when true.\n\n#### `isFailure\u003cFailureValue\u003e(result: Result\u003cunknown, FailureValue\u003e): result is Failure\u003cFailureValue\u003e`\n\n- A type guard function that checks if a given result is a failure.\n- Returns `true` if the result is a failure, otherwise `false`.\n- Assists in type narrowing to `Failure\u003cFailureValue\u003e` when the result is a failure.\n\n#### `unwrap\u003cSuccessValue, FailureValue\u003e(result: Result\u003cSuccessValue, FailureValue\u003e): FailureValue | SuccessValue`\n\n- Extracts the value from a success or failure result.\n- Simplifies the process of accessing the underlying value of a result.\n- **Parameters:**\n  - `result`: The `Result` instance from which the value should be unwrapped.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request for any features or fixes.\n\n## License\n\nThis project is licensed under the MIT License.\n\n---\n\nScaffolded with [@skarab/skaffold](https://www.npmjs.com/package/@skarab/skaffold)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskarab42%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskarab42%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskarab42%2Fresult/lists"}