{"id":29091262,"url":"https://github.com/fredericoo/fx-nano","last_synced_at":"2025-07-26T04:03:10.587Z","repository":{"id":301125416,"uuid":"1008237324","full_name":"fredericoo/fx-nano","owner":"fredericoo","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-30T21:09:04.000Z","size":99,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-24T20:42:06.833Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fredericoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"fredericoo"}},"created_at":"2025-06-25T08:33:05.000Z","updated_at":"2025-06-30T21:09:08.000Z","dependencies_parsed_at":"2025-06-25T09:49:17.464Z","dependency_job_id":null,"html_url":"https://github.com/fredericoo/fx-nano","commit_stats":null,"previous_names":["fredericoo/fx-nano"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fredericoo/fx-nano","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Ffx-nano","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Ffx-nano/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Ffx-nano/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Ffx-nano/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fredericoo","download_url":"https://codeload.github.com/fredericoo/fx-nano/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Ffx-nano/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267116124,"owners_count":24038623,"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-07-26T02:00:08.937Z","response_time":62,"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":[],"created_at":"2025-06-28T06:06:30.660Z","updated_at":"2025-07-26T04:03:10.558Z","avatar_url":"https://github.com/fredericoo.png","language":"TypeScript","funding_links":["https://github.com/sponsors/fredericoo"],"categories":[],"sub_categories":[],"readme":"# fx-nano\n\nhyper lightweight (300bytes gzip) typesafe error library loosely inspired by golang and effect\n\n## incremental adoption\n\nno need to rewrite your whole app. you can start with smaller and simpler functions at the edges of your app just fine\n\n## true error type-safety\n\neven the most robust libraries don’t actually return type-safe errors because they fail to consider javascript’s goblin nature\n\ne.g.:\n```ts\nconst getPokemonSpriteImage = async (name: string): string =\u003e {\n  const res = await fetch(`https://pokeapi.co/api/v2/${name}`);\n  const json = await res.json();\n  if (typeof json.sprites.front_default === 'string') return json.sprites.front_default;\n  throw new Error(\"Missing sprite\");\n}\n```\n\nthis function seems harmless and straightforward. it could still fail in many ways:\n- requester has no connection (e.g.: \"Fetch failed\")\n- response is not json (e.g.: \"Unexpected token '\u003c' at position 0\")\n- `json.sprites` does not exist\n- `json.sprites.front_default` does not exist\n\nyou can make it type-safe by first returning `fx.ok` or `fx.fail`:\n```ts\nimport { fx } from \"fx-nano\";\n\nconst getPokemonSpriteImage = async (name: string): Result\u003c\"Missing sprite\", string\u003e =\u003e {\n  const res = await fetch(`https://pokeapi.co/api/v2/${name}`);\n  const json = await res.json();\n  if (typeof json.sprites.front_default === 'string') return fx.ok(json.sprites.front_default);\n  return fx.fail(\"Missing sprite\");\n}\n```\n\nand then when you need to use it, wrap it in `fx.runPromise`:\n\n```ts\nimport { fx } from \"fx-nano\";\n\nconst getPokemonSpriteImage = async (name: string) =\u003e {\n  const res = await fetch(`https://pokeapi.co/api/v2/${name}`);\n  const json = await res.json();\n  if (typeof json.sprites.front_default === 'string') return fx.ok(json.sprites.front_default);\n  return fx.fail(\"Missing sprite\");\n}\n\n// in your app\n\nconst main = () =\u003e {\n  const [error, sprite] = fx.runPromise(getPokemonSprite('ditto'));\n}\n```\n\n\n## Installation\n\n```bash\nnpm add fx-nano\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredericoo%2Ffx-nano","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffredericoo%2Ffx-nano","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredericoo%2Ffx-nano/lists"}