{"id":17717927,"url":"https://github.com/mamal72/ifexpr","last_synced_at":"2025-03-31T12:25:31.563Z","repository":{"id":57271453,"uuid":"286077943","full_name":"mamal72/ifexpr","owner":"mamal72","description":"Simple functional library to offer if conditions as expressions, not statements","archived":false,"fork":false,"pushed_at":"2020-08-08T16:39:58.000Z","size":293,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T14:56:30.125Z","etag":null,"topics":["functional-programming","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"https://mamal72.github.io/ifexpr","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/mamal72.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-08T16:20:48.000Z","updated_at":"2021-01-03T19:38:06.000Z","dependencies_parsed_at":"2022-09-13T21:20:39.828Z","dependency_job_id":null,"html_url":"https://github.com/mamal72/ifexpr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamal72%2Fifexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamal72%2Fifexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamal72%2Fifexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mamal72%2Fifexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mamal72","download_url":"https://codeload.github.com/mamal72/ifexpr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246466968,"owners_count":20782229,"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":["functional-programming","typescript","typescript-library"],"created_at":"2024-10-25T14:32:58.784Z","updated_at":"2025-03-31T12:25:31.540Z","avatar_url":"https://github.com/mamal72.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![NPM](https://img.shields.io/npm/l/ifexpr) [![Build Status](https://travis-ci.com/mamal72/ifexpr.svg?branch=master)](https://travis-ci.com/mamal72/ifexpr) [![codecov](https://codecov.io/gh/mamal72/ifexpr/branch/master/graph/badge.svg)](https://codecov.io/gh/mamal72/ifexpr) ![David](https://img.shields.io/david/mamal72/ifexpr) ![npm](https://img.shields.io/npm/v/ifexpr) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/ifexpr) ![npm](https://img.shields.io/npm/dm/ifexpr)\n\n# ifexpr\n\nA simple functional library to offer **if** conditions as **expressions**, **not statements**.\n\n\n## Installation\n\nUsing NPM:\n\n```sh\nnpm i ifexpr\n```\n\nUsing Yarn:\n\n```sh\nyarn add ifexpr\n```\n\n\n## Usage\n\n### Description\n\n\u003e Note that this module has been developed using TypeScript with proper typings. So you mostly don't need to read this part and you can skip to examples section to see some real usages.\n\nYou need to pass a `boolean` or a `() =\u003e boolean` as first param.\n\nThe next 2 params can be a `T` or a `() =\u003e T`. First one will be returned/executed and returned as expression value if the passed condition/condition function is/returns truthy. The last one will be returned/executed and returned as expression value if the passed condition/condition function is/returns falsy.\n\n### Examples:\n\n```ts\nimport ifexpr from 'ifexpr'\n\nconst age = 20\n\nconst isOldEnough = ifexpr(age \u003e 18, true, false) // returns true\nconst isOldEnough2 = ifexpr(() =\u003e {\n  return age \u003e 18\n}, true, false) // returns true\n\nconst isOldEnough3 = ifexpr\u003c'yes' | 'no'\u003e(age \u003e 18, () =\u003e {\n  // some other stuff to execute in case of truthy\n  return 'yes'\n}, () =\u003e {\n  // some other stuff to execute in case of falsy\n  return 'no'\n}) // returns 'yes'\n```\n\n### More examples:\n\nYou can check unit tests inside `src` directory to read all possible usages.\n\n\n## Contribution\n\nYou can report bugs and issues [here](https://github.com/mamal72/ifexpr/issues/new).\n\nYou can also send a PR if you feel like you can improve or fix something. Don't forget to write/update tests for your changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamal72%2Fifexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmamal72%2Fifexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmamal72%2Fifexpr/lists"}