{"id":16484498,"url":"https://github.com/tungv/brn","last_synced_at":"2025-03-21T07:30:59.569Z","repository":{"id":27305987,"uuid":"113282073","full_name":"tungv/brn","owner":"tungv","description":"Functional flow control","archived":false,"fork":false,"pushed_at":"2023-03-06T13:24:22.000Z","size":1093,"stargazers_count":8,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T13:52:37.537Z","etag":null,"topics":["conditional","functional","if-else","nodejs"],"latest_commit_sha":null,"homepage":"https://npm.im/brn","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/tungv.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}},"created_at":"2017-12-06T07:13:09.000Z","updated_at":"2023-03-08T14:01:07.000Z","dependencies_parsed_at":"2024-06-19T15:19:57.255Z","dependency_job_id":"6f8c2cdb-d392-4340-9421-3247a4ab7008","html_url":"https://github.com/tungv/brn","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungv%2Fbrn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungv%2Fbrn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungv%2Fbrn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungv%2Fbrn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tungv","download_url":"https://codeload.github.com/tungv/brn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757405,"owners_count":20505389,"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":["conditional","functional","if-else","nodejs"],"created_at":"2024-10-11T13:17:20.517Z","updated_at":"2025-03-21T07:30:59.237Z","avatar_url":"https://github.com/tungv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strongly Typed Functional Branching\n\n`brn` exports only one function that takes a `test`, a `left`, and a `right`\nfunction and return a combined one that will run `left` if `test` returns truthy\nand `right` otherwise\n\n# Example\n\n```js\nconst brn = require('brn');\n\nconst isOdd = x =\u003e x % 2;\n\nconst left = x =\u003e `${x} is odd`;\nconst right = x =\u003e `${x} is even`;\n\nconst fn = brn(isOdd, left, right);\n\nconsole.log(fn(2)); // returns 2 is even\nconsole.log(fn(1)); // returns 1 is odd\n```\n\n# TypeScript\n\n```ts\nimport brn from 'brn'\n\nconst isOdd = (x: number) =\u003e x % 2;\n\nconst fn = brn(\n  isOdd,\n  x =\u003e `${x} is odd` as const,\n  x =\u003e `${x} is even` as const\n);\n\nexpect(fn(2, 'two')).toBe('2 is even'); // returns 2 is even\nexpect(fn(1, 'one')).toBe('1 is odd'); // returns 1 is odd\n```\n\nIn this example, parameter `x` in the \"left\" and \"right\" functions is typed as `number`.\n`fn` also has return type of `` `${number} is even` | `${number} is odd` ``\n\n\n```ts\n// another example\nfunction always\u003cX extends string\u003e(x: X) {\n  return () =\u003e x;\n}\nconst fn = brn(\n  (x: number) =\u003e x \u003e= 10,\n  always(`double digit`),\n  brn(\n    x =\u003e x \u003c 0,\n    always('negative'),\n    always('single digit')\n  )\n)\n```\n\nIn this example, return type of `fn` is one of `\"single digit\"`, `\"double digit\"` or `\"negative\"`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftungv%2Fbrn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftungv%2Fbrn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftungv%2Fbrn/lists"}