{"id":13393831,"url":"https://github.com/erikmueller/cond-flow","last_synced_at":"2025-05-07T17:42:20.450Z","repository":{"id":42915823,"uuid":"248846849","full_name":"erikmueller/cond-flow","owner":"erikmueller","description":"Elixir style cond for easy javascript control flow","archived":false,"fork":false,"pushed_at":"2024-12-14T02:06:48.000Z","size":334,"stargazers_count":38,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-17T11:02:57.410Z","etag":null,"topics":["conditions","flow-control","utilities"],"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/erikmueller.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":"2020-03-20T20:33:35.000Z","updated_at":"2023-11-14T16:51:35.000Z","dependencies_parsed_at":"2023-12-06T09:28:09.094Z","dependency_job_id":"ccf18da9-d7a3-4dfa-84d2-58e1cbe4512e","html_url":"https://github.com/erikmueller/cond-flow","commit_stats":{"total_commits":48,"total_committers":4,"mean_commits":12.0,"dds":0.6666666666666667,"last_synced_commit":"be4620557a89cac346223499dab0ec939579b27c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikmueller%2Fcond-flow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikmueller%2Fcond-flow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikmueller%2Fcond-flow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikmueller%2Fcond-flow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erikmueller","download_url":"https://codeload.github.com/erikmueller/cond-flow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240783138,"owners_count":19856780,"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":["conditions","flow-control","utilities"],"created_at":"2024-07-30T17:01:01.057Z","updated_at":"2025-02-26T03:15:38.998Z","avatar_url":"https://github.com/erikmueller.png","language":"TypeScript","readme":"# cond-flow\n\nInspired by [Elixir's `cond`](https://elixir-lang.org/getting-started/case-cond-and-if.html#cond) this is a simpler alternative to [lodash's `_.cond`](https://lodash.com/docs/4.17.15#cond)\n\n[![codecov](https://codecov.io/gh/erikmueller/cond-flow/branch/master/graph/badge.svg?token=WCNYJSZK51)](https://codecov.io/gh/erikmueller/cond-flow)\n\n## Install\n\nInstall with npm or yarn via\n\n```sh\nyarn add cond-flow\n```\n\nor\n\n```sh\nnpm i cond-flow\n```\n\n## Usage\n\n```js\nimport cond from 'cond-flow'\n\nconst value = cond([\n  [false, 'false'],\n  [true, 'true'],\n  [true, 'true but too late'],\n])\n\n// value === 'true'\n```\n\nAlso works nicely with React components as you can have the values lazily evaluated by wrapping them in a function:\n\n```jsx\nimport cond from 'cond-flow'\n\nconst Component = ({ isDisabled, isNew, isLoading }) =\u003e (\n  \u003c\u003e\n    {cond([\n      [isLoading, () =\u003e \u003cLoading /\u003e],\n      [isNew, () =\u003e \u003cCreate /\u003e],\n      [isDisabled, null],\n    ])}\n  \u003c/\u003e\n)\n```\n\n### Default return value\n\nYou can provide a `default` fallback which will be returned if no provided conditions are met.\n\n```js\nimport cond from 'cond-flow'\n\nconst value = cond(\n  [\n    [false, () =\u003e 'false'],\n    [false, () =\u003e 'also false'],\n  ],\n  { default: () =\u003e 'fallback' },\n)\n\n// value === 'fallback'\n```\n\n### Note\n\nAs all predicates have to be evaluated before the right branch can be chosen, it can have a negative performance impact if you rely on heavy computations. It's best to have simple booleans and resort to [Ramda's](https://ramdajs.com/docs/#cond) `cond` for complex use cases.\n\n## Development\n\nIf you find this useful or would like to add features, feel free to clone the repository and open a PR.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikmueller%2Fcond-flow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikmueller%2Fcond-flow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikmueller%2Fcond-flow/lists"}