{"id":17114661,"url":"https://github.com/mudssrali/cond-construct","last_synced_at":"2026-05-01T10:32:34.845Z","repository":{"id":57205208,"uuid":"260578418","full_name":"mudssrali/cond-construct","owner":"mudssrali","description":"Elixir's cond construct implementation for Javascript and Typescript ","archived":false,"fork":false,"pushed_at":"2022-09-28T19:03:09.000Z","size":127,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-21T23:14:18.276Z","etag":null,"topics":["cond","control-flow","elixir-cond","elixir-lang","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mudssrali.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-01T23:30:43.000Z","updated_at":"2023-01-17T21:01:04.000Z","dependencies_parsed_at":"2022-09-18T01:32:29.523Z","dependency_job_id":null,"html_url":"https://github.com/mudssrali/cond-construct","commit_stats":null,"previous_names":["mudassar045/cond-construct"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mudssrali/cond-construct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fcond-construct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fcond-construct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fcond-construct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fcond-construct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mudssrali","download_url":"https://codeload.github.com/mudssrali/cond-construct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fcond-construct/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32494270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["cond","control-flow","elixir-cond","elixir-lang","javascript","typescript"],"created_at":"2024-10-14T17:19:42.699Z","updated_at":"2026-05-01T10:32:34.824Z","avatar_url":"https://github.com/mudssrali.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cond-construct\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[![CI status](https://circleci.com/gh/mudssrali/cond-construct.svg?style=shield)](LINK)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n\u003ca aria-label=\"Package size\" href=\"https://bundlephobia.com/result?p=cond-construct\"\u003e\n  \u003cimg alt=\"\" src=\"https://badgen.net/bundlephobia/minzip/cond-construct\"\u003e\n\u003c/a\u003e\n\n## Install\n\nInstall with npm or yarn via\n\n```\nyarn add cond-construct\n```\n\nor\n\n```\nnpm i cond-construct\n```\n\n## API\n\n```ts\ntype Cond = (\n  pairs: Array\u003c[boolean, unknown | (() =\u003e unknown)]\u003e,\n  options?: { strict: boolean }\n) =\u003e unknown\n```\n\n## Usage\n\n```js\nimport cond from 'cond-construct'\n\nconst value = cond([\n  [false, 'false'],\n  [true, 'true'],\n  [true, 'true but too late']\n])\n\n// value === 'true'\n```\n\nYou can disable strict checking by passing options as the second argument:\n\n```js\nimport cond from 'cond-construct'\n\nconst value = cond(\n  [\n    [false, 'false'],\n    [1, 'truthy'],\n    [true, 'true but also too late']\n  ],\n  { strict: false }\n)\n\n// value === 'truthy'\n```\n\nAlso works nicely with React components as you can have the values lazily evaluated by wrapping it in a function:\n\n```jsx\nimport cond from 'cond-construct'\n\nconst Component = ({ hasErrors, isNew, isLoading }) =\u003e (\n  \u003c\u003e\n    {cond([\n      [isLoading, () =\u003e \u003cLoading /\u003e],\n      [isNew, () =\u003e \u003cCreate /\u003e],\n      [hasErrors, () =\u003e \u003cShowErrors /\u003e]\n    ])}\n  \u003c/\u003e\n)\n```\n\n### Next\n\n- [] Handle multiple method executions\n- [] Add more option for falsy value\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 here. It's best have simple booleans and resort to `_.cond` for complex use cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudssrali%2Fcond-construct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmudssrali%2Fcond-construct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudssrali%2Fcond-construct/lists"}