{"id":22404776,"url":"https://github.com/jdeurt/inline-conditional","last_synced_at":"2025-10-13T06:21:05.023Z","repository":{"id":60867740,"uuid":"546275796","full_name":"jdeurt/inline-conditional","owner":"jdeurt","description":"Create inline conditional statements!","archived":false,"fork":false,"pushed_at":"2023-01-14T19:24:46.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-25T18:41:36.471Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/jdeurt.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-10-05T20:36:24.000Z","updated_at":"2024-04-22T00:25:55.000Z","dependencies_parsed_at":"2023-02-09T20:15:55.277Z","dependency_job_id":null,"html_url":"https://github.com/jdeurt/inline-conditional","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":"jdeurt/ts-module-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeurt%2Finline-conditional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeurt%2Finline-conditional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeurt%2Finline-conditional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdeurt%2Finline-conditional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdeurt","download_url":"https://codeload.github.com/jdeurt/inline-conditional/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245761302,"owners_count":20667895,"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-12-05T10:15:09.065Z","updated_at":"2025-10-13T06:20:59.990Z","avatar_url":"https://github.com/jdeurt.png","language":"TypeScript","readme":"[![npm version](https://badge.fury.io/js/inline-conditional.svg)](https://badge.fury.io/js/inline-conditional)\n\n# Inline Conditional\n\n\u003e Create inline conditional statements!\n\n## Table of contents\n\n-   [Inline Conditional](#inline-conditional)\n    -   [Table of contents](#table-of-contents)\n    -   [Installation](#installation)\n    -   [Usage](#usage)\n        -   [Vanilla JS](#vanilla-js)\n        -   [React](#react)\n    -   [API](#api)\n    -   [Authors](#authors)\n    -   [License](#license)\n\n## Installation\n\nTo install, run:\n\n```sh\n$ npm install inline-conditional\n```\n\nOr if you prefer using Yarn:\n\n```sh\n$ yarn add inline-conditional\n```\n\n## Usage\n\nThis library allows you to write if/else and switch statements as expressions. This means that you can use them in places where you would normally use a value, most commonly in front-end development scenarios.\n\nWhy use this over a ternary expression? I'll show you:\n\n```js\nchar === \"a\"\n    ? 1\n    : char === \"b\"\n    ? 2\n    : char === \"c\"\n    ? someCondition\n        ? 3\n        : 4\n    : 0;\n\n// vs\n\nInline.switch(char)\n    .case(\"a\")(1)\n    .case(\"b\")(2)\n    .case(\"c\")(Inline.if(someCondition)(3).else(4))\n    .default(0);\n```\n\n### Vanilla JS\n\n```js\nimport { Inline } from \"inline-conditional\";\n\nconst inlineIfResult = Inline.if(something === somethingElse)(1)\n    .elseIf(something.property === expectedPropertyValue)(2)\n    .else(3);\n\nconst inlineSwitchResult = Inline.switch(flag)\n    .case(1)(\"Hello 1!\")\n    .case(2)(\"Hello 2!\")\n    .default(\"Who are you?\");\n```\n\n### React\n\n```jsx\nconst Page = () =\u003e {\n    const isLoggedIn = useSomeAuthenticationHook();\n\n    return (\n        \u003cTemplate\u003e\n            {Inline.if(isLoggedIn)(\n                // Use functions to prevent components from being called when they're not relevant\n                () =\u003e \u003cUserPage /\u003e\n            ).else(() =\u003e \u003cAccessDenied /\u003e)()}\n        \u003c/Template\u003e\n    );\n};\n```\n\n## API\n\n**TODO**\n\nFor now, all methods are well-documented using JSDoc.\n\n## Authors\n\n-   **Juan de Urtubey** - - [jdeurt](https://github.com/jdeurt)\n\n## License\n\nMIT © [Juan de Urtubey](https://github.com/jdeurt)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdeurt%2Finline-conditional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdeurt%2Finline-conditional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdeurt%2Finline-conditional/lists"}