{"id":23297542,"url":"https://github.com/drag13/whendo","last_synced_at":"2025-10-25T14:11:07.794Z","repository":{"id":29147891,"uuid":"120300397","full_name":"Drag13/WhenDo","owner":"Drag13","description":"Small function that can be used instead if-then statement in functional style programming with JavaScript","archived":false,"fork":false,"pushed_at":"2023-03-04T02:45:30.000Z","size":150,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T21:17:02.341Z","etag":null,"topics":["conditional-statements","development","functional-programming","ifthen","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Drag13.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":"2018-02-05T12:15:10.000Z","updated_at":"2022-01-26T07:03:43.000Z","dependencies_parsed_at":"2024-12-20T07:19:12.104Z","dependency_job_id":"848ce296-09d2-4a9f-9090-f40617a48366","html_url":"https://github.com/Drag13/WhenDo","commit_stats":{"total_commits":68,"total_committers":4,"mean_commits":17.0,"dds":0.4852941176470589,"last_synced_commit":"20731e2346103f7d4377cf707fc69e193b80d2b9"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/Drag13/WhenDo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Drag13%2FWhenDo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Drag13%2FWhenDo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Drag13%2FWhenDo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Drag13%2FWhenDo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Drag13","download_url":"https://codeload.github.com/Drag13/WhenDo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Drag13%2FWhenDo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261487352,"owners_count":23166069,"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-statements","development","functional-programming","ifthen","javascript"],"created_at":"2024-12-20T07:18:26.010Z","updated_at":"2025-10-25T14:11:02.742Z","avatar_url":"https://github.com/Drag13.png","language":"JavaScript","readme":"# WhenDo\n\n[![Coverage Status](https://coveralls.io/repos/github/Drag13/WhenDo/badge.svg?branch=coverage)](https://coveralls.io/github/Drag13/WhenDo?branch=coverage)\n[![Build Status](https://travis-ci.org/Drag13/WhenDo.svg?branch=master)](https://travis-ci.org/Drag13/WhenDo)\n[![npm](https://img.shields.io/npm/dt/@drag13/when-do.svg)](https://github.com/Drag13/WhenDo)\n[![TypeSCript](https://img.shields.io/badge/TypeScript-Ready-brightgreen.svg)](https://github.com/Drag13/WhenDo)\n[![GitHub license](https://img.shields.io/github/license/Drag13/WhenDo.svg)](https://github.com/Drag13/WhenDo/blob/master/LICENSE)\n\n## Description\n\nSmall function that can be used instead of 'if-then' statement in functional style programming with JavaScript. Takes a predicate and one or two handlers. Returns new function that will check the predicate and execute a true/false handler.\n\nNo external dependencies, uses ES6 inside, TypeScript ready.\n\n## Installation\n\n  `npm install @drag13/when-do`\n\n## Usage\n\nUsage is simple: WhenDo function returns a new function that will be executed depending on a predicate. You can pass params and expect return result.\n\n``` javascript\nconst wd = require('@drag13/when-do');\nconst myComposedFunction = wd(() =\u003e true, (name) =\u003e `hello ${name}`);\nconsole.assert(myComposedFunction('mate') === 'hello mate');\n```\n\nIf you pass a predicate as a function, it will not be invoked until composed function call is executed.\n\n``` javascript\nconst wd = require('@drag13/when-do');\nconst log = console.log;\nconst demo = wd(()=\u003e { log('predicate calculated');  return true;},\n                ()=\u003e log('trueFunction executed'));\nlog('start');\ndemo();\n```\n\nResult will be\n\n  `start`\n\n  `predicate calculated`\n\n  `trueFunction executed`\n\n## React\n\nIf you want to have if-then-else statement inside react - try this example\n\n```jsx\nimport iftrue from '@drag13/when-do';\n\nrender() {\n    return (\n        \u003cdiv className=\"WhenDoExample\"\u003e\n            {\n                iftrue(this.state.counter % 2,\n                    () =\u003e \u003cdiv\u003eOdd\u003c/div\u003e,\n                    () =\u003e \u003cdiv\u003eEven\u003c/div\u003e)()\n            }\n            \u003cbutton onClick={() =\u003e this.setState({ counter: this.state.counter + 1 })}\u003eCLICK\u003c/button\u003e\n        \u003c/div\u003e\n    );\n}\n\n```\n\n*Tip:* You can name WhenDo function whatever you want, just change name inside the import!\n\n```javascript\nimport ifthenelse from '@drag13/when-do';\nimport iftrue from '@drag13/when-do'\n\n```\n    \n## TypeScript\n\nFeel free to use it with TypeScript\n\n``` typescript\nimport * as whenDo from '@drag13/when-do';\nconst myComposedFunction = wd(() =\u003e true, (name) =\u003e `hello ${name}`);\nconsole.assert(myComposedFunction('mate') === 'hello mate');\n```\n\n## Tests\n\n  `npm test`\n\n## Contributing\n\nAny bug fixing is appreciated. If you want to add new functionality - you're welcome. But KISS it please.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrag13%2Fwhendo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrag13%2Fwhendo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrag13%2Fwhendo/lists"}