{"id":15492133,"url":"https://github.com/imjuni/my-only-either","last_synced_at":"2025-07-30T00:34:08.898Z","repository":{"id":50023261,"uuid":"488278067","full_name":"imjuni/my-only-either","owner":"imjuni","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-30T17:28:11.000Z","size":432,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-20T14:55:55.389Z","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/imjuni.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}},"created_at":"2022-05-03T16:10:17.000Z","updated_at":"2023-03-17T13:00:09.000Z","dependencies_parsed_at":"2022-08-29T15:11:37.639Z","dependency_job_id":null,"html_url":"https://github.com/imjuni/my-only-either","commit_stats":null,"previous_names":["imjuni/my-simple-either"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjuni%2Fmy-only-either","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjuni%2Fmy-only-either/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjuni%2Fmy-only-either/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjuni%2Fmy-only-either/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imjuni","download_url":"https://codeload.github.com/imjuni/my-only-either/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299850,"owners_count":20916193,"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":[],"created_at":"2024-10-02T07:58:58.994Z","updated_at":"2025-04-05T07:12:03.693Z","avatar_url":"https://github.com/imjuni.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# my-only-either\n\n[![Download Status](https://img.shields.io/npm/dw/my-only-either.svg)](https://npmcharts.com/compare/my-only-either?minimal=true) [![Github Star](https://img.shields.io/github/stars/imjuni/my-only-either.svg?style=popout)](https://github.com/imjuni/my-only-either) [![Github Issues](https://img.shields.io/github/issues-raw/imjuni/my-only-either.svg)](https://github.com/imjuni/my-only-either/issues) [![NPM version](https://img.shields.io/npm/v/my-only-either.svg)](https://www.npmjs.com/package/my-only-either) [![License](https://img.shields.io/npm/l/my-only-either.svg)](https://github.com/imjuni/my-only-either/blob/master/LICENSE)\n\nSimple Type and Function set for Either interface. Either important concept in functional programming. But Node.js and TypeScript don't have implmentation. So you can choose another functional implementation like [fp-ts](https://github.com/gcanti/fp-ts) or anther functional utility. But if you need only Eihter, this package is good alternative.\n\n# Why? use Either?\n\n## Zero Dependency\nmy-only-either not use package. only 1k(1,489byte) size.\n\n## Help functional programming\nHelpful for functional programming and integrate return type. See below.\n\n```ts\nimport { parse as jsoncParse } from 'jsonc-parser';\nimport { parse as json5Parse } from 'json5';\n\nfunction json5Parse(value: string): PassFailEither\u003cError, Record\u003cany, any\u003e\u003e {\n  try {\n    return pass(json5Parse(value));\n  } catch (err) {\n    return fail(new Error(err));\n  }\n}\n\nfunction jsoncParse(value: string): PassFailEither\u003cError, Record\u003cany, any\u003e\u003e {\n  try {\n    return pass(jsoncParse(value));\n  } catch (err) {\n    return fail(new Error(err));\n  }\n}\n\nfunction parse(value: string): Record\u003cany, any\u003e {\n  const jsoncParsedEither = jsoncParse(value);\n\n  if (isPass(jsoncParsedEither)) {\n    return jsoncParsedEither.pass;\n  }\n\n  const json5ParsedEither = json5Parse(value);\n\n  if (isPass(json5ParsedEither)) {\n    return json5ParsedEither.pass;    \n  }\n\n  throw new Error(json5ParsedEither.fail);\n}\n```\n\nthrow keyword move control-flow. But Either, PassFailEither don't move control-flow besides Either helpful functional programming and function pipe.\n\n# Either\nName using left and right.\n\n| name | category | description |\n| :- | :-: | :- |\n| ILeft | type | Left interface |\n| IRight | type | Right interface |\n| Either | type | Either type using ILeft and IRight |\n| TPickLeft | utility type | Return Type of left in Either |\n| TPickILeft | utility type | Return Type of ILeft in Either |\n| TPickRight | utility type | Return Type of right in Either |\n| TPickIRight | utility type | Return Type of IRight in Either |\n| left | function | value convert ILeft type |\n| right | function | value convert IRight type |\n| isLeft | function | check given value is ILeft type |\n| isRight | function | check given value is IRight type |\n\n# PassFailEither\nName using pass and fail.\n\n| name | category | description |\n| :-: | :-: | :- |\n| IFail | type | Fail interface |\n| IPass | type | Pass interface |\n| PassFailEither | type | PassFailEither type using IFail and IPass |\n| TPickFail | utility type | Return Type of fail in Either |\n| TPickIFail | utility type | Return Type of IFail in Either |\n| TPickPass | utility type | Return Type of pass in Either |\n| TPickIPass | utility type | Return Type of IPass in Either |\n| fail | function | value convert IFail type |\n| pass | function | value convert IPass type |\n| efail | function | value convert IFail type, exactly same fail. If you use jest or test runner this function is helpful for auto import \u0026 auto complete |\n| epass | function | value convert IPass type, exactly same pass. If you use jest or test runner this function is helpful for auto import \u0026 auto complete |\n| isFail | function | check given value is IFail type |\n| isPass | function | check given value is IPass type |\n\n# Type order in Eiter, PassFailEither\nFirst type arguments is ILeft or IFail. Because fp-ts and many functional programming language choose first type is left(or fail).\n\n```ts\ntype Either\u003cTLEFT, TRIGHT\u003e = ILeft\u003cTLEFT\u003e | IRight\u003cTRIGHT\u003e;\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimjuni%2Fmy-only-either","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimjuni%2Fmy-only-either","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimjuni%2Fmy-only-either/lists"}