{"id":22021590,"url":"https://github.com/lamansky/roadblock","last_synced_at":"2025-08-11T17:08:48.663Z","repository":{"id":92612047,"uuid":"84089117","full_name":"lamansky/roadblock","owner":"lamansky","description":"[Node.js] A simple function for interrupting program flow if a condition isn’t met","archived":false,"fork":false,"pushed_at":"2018-11-03T15:20:31.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T15:32:53.738Z","etag":null,"topics":["control-flow","javascript","nodejs"],"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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","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":"2017-03-06T15:26:58.000Z","updated_at":"2018-11-03T15:20:32.000Z","dependencies_parsed_at":"2023-03-18T20:04:55.022Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/roadblock","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"cd6a83af2d07631e3a2f7a35b375c7d4d98d375c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/lamansky/roadblock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Froadblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Froadblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Froadblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Froadblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/roadblock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Froadblock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269793972,"owners_count":24476732,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"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":["control-flow","javascript","nodejs"],"created_at":"2024-11-30T06:13:09.370Z","updated_at":"2025-08-11T17:08:48.628Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# roadblock\n\nA simple function for interrupting program flow if a condition isn’t met.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 4.0.0 or above.\n\n```bash\nnpm i roadblock\n```\n\n## API\n\nThe module exposes a single function:\n\n```javascript\nmodule.exports = (shouldBlock, block, main) =\u003e shouldBlock ? block(main) : main()\n```\n\nIf `shouldBlock` is true, then the `block` function is called and is given `main` as an argument, to be invoked when/if `block` is ready. If `shouldBlock` is false, `block` is bypassed and `main` is called immediately.\n\n## Example\n\n```javascript\nconst roadblock = require('roadblock')\n\nroadblock(!loggedIn, main =\u003e {\n  // show login form\n  if (loginSuccessful) main()\n}, () =\u003e {\n  // show user-only page\n})\n```\n\nIn the above example, if `loggedIn` is false, the login function is invoked, and is given a callback which it can use once the login is successful. If, on the other hand, `loggedIn` is true, then the login function is bypassed and the main function is called directly.\n\n### The Alternative\n\nWithout `roadblock`, the code for the previous example would look something like this:\n\n```javascript\nfunction login () {\n  // show login form\n  if (loginSuccessful) main()\n}\n\nfunction main () {\n  // show user-only page\n}\n\nif (loggedIn) {\n  main()\n} else {\n  login()\n}\n```\n\n`roadblock` is intended to make your code more compact, more sequential, and less cluttered with named functions that are used only once or twice.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Froadblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Froadblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Froadblock/lists"}