{"id":30876880,"url":"https://github.com/duydang2311/attempt","last_synced_at":"2026-01-20T16:49:02.074Z","repository":{"id":300360839,"uuid":"1005985257","full_name":"duydang2311/attempt","owner":"duydang2311","description":"Dead simple Go-like error handling for JS, TS.","archived":false,"fork":false,"pushed_at":"2025-08-16T14:04:10.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-16T15:25:32.685Z","etag":null,"topics":["attempt","error-handling","result-pattern","try","try-catch"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@duydang2311/attempt","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/duydang2311.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-06-21T08:22:39.000Z","updated_at":"2025-08-16T14:04:12.000Z","dependencies_parsed_at":"2025-06-21T08:50:09.373Z","dependency_job_id":"b7d48121-5b8a-4fdb-a144-e07534b8e29c","html_url":"https://github.com/duydang2311/attempt","commit_stats":null,"previous_names":["duydang2311/attempt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/duydang2311/attempt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duydang2311%2Fattempt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duydang2311%2Fattempt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duydang2311%2Fattempt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duydang2311%2Fattempt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duydang2311","download_url":"https://codeload.github.com/duydang2311/attempt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duydang2311%2Fattempt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274130221,"owners_count":25227272,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["attempt","error-handling","result-pattern","try","try-catch"],"created_at":"2025-09-08T03:48:38.582Z","updated_at":"2026-01-20T16:49:02.068Z","avatar_url":"https://github.com/duydang2311.png","language":"TypeScript","readme":"# @duydang2311/attempt\n\n[![@duydang2311/attempt's badge](https://deno.bundlejs.com/?q=@duydang2311/attempt\u0026badge=detailed\u0026badge-style=for-the-badge)](https://bundlejs.com/?q=@duydang2311/attempt)\n\nFunctional error handling for JavaScript and TypeScript. Inspired by \"Error as Value\" in functional programming, `attempt` provides a clean, predictable way to manage operations that can succeed or fail.\n\n## Installation\n\n```bash\nbun add @duydang2311/attempt\n```\n\n## Usage\n\n```typescript\nimport { attempt } from '@duydang2311/attempt';\n\nconst divideUnsafe = (a: number, b: number) =\u003e {\n    if (b === 0) { throw new Error(\"Can't divide by zero!\"); }\n    return a / b;\n};\n\nconst divideSafe = (a: number, b: number) =\u003e {\n    if (b === 0) { return attempt.fail('ERR_DIVIDE_BY_ZERO'); }\n    return attempt.ok(a / b);\n};\n\nconst resultUnsafe = divideUnsafe(10, 2); // number (might throw)\nconst resultSafe = attempt.sync(() =\u003e divideUnsafe(10, 2))(); // Attempt\u003cnumber, unknown\u003e\n\n// assuming divide by zero is the only exception that might happen\nconst resultSafeBetter = attempt.sync(() =\u003e divideUnsafe(10, 2))(e =\u003e 'ERR_DIVIDE_BY_ZERO'); // Attempt\u003cnumber, 'ERR_DIVIDE_BY_ZERO'\u003e\n\nconst resultSafeEvenBetter = divideSafe(10, 2); // Attempt\u003cnumber, 'ERR_DIVIDE_BY_ZERO'\u003e\n\n// do some operations the functional way\nconst output = resultSafeEvenBetter.pipe(\n    attempt.map(a =\u003e `Success: ${a}`),\n    attempt.unwrapOrElse(e =\u003e `Error: ${e}`)\n); // string\n\nconsole.log(output);\n```\n\n## License\nMIT License. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduydang2311%2Fattempt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduydang2311%2Fattempt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduydang2311%2Fattempt/lists"}