# roadblock

> A simple function for interrupting program flow if a condition isn’t met.

Latest version **1.1.0** (published 2018-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install roadblock
pnpm add roadblock
yarn add roadblock
bun add roadblock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-11-03 |
| First published | 2017-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Fr. John Lamansky |
| Maintainers | lamansky |
| Keywords | flow, control flow, program flow, precede, interrupt, halt, stop, check |

## Links

- npm: https://www.npmjs.com/package/roadblock
- Repository: https://github.com/lamansky/roadblock
- Issues: https://github.com/lamansky/roadblock/issues
- npm.io page: https://npm.io/package/roadblock

## Recent versions

- 1.1.0 (latest) — 2018-11-03
- 1.0.0 — 2017-03-06

## README

# roadblock

A simple function for interrupting program flow if a condition isn’t met.

## Installation

Requires [Node.js](https://nodejs.org/) 4.0.0 or above.

```bash
npm i roadblock
```

## API

The module exposes a single function:

```javascript
module.exports = (shouldBlock, block, main) => shouldBlock ? block(main) : main()
```

If `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.

## Example

```javascript
const roadblock = require('roadblock')

roadblock(!loggedIn, main => {
  // show login form
  if (loginSuccessful) main()
}, () => {
  // show user-only page
})
```

In 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.

### The Alternative

Without `roadblock`, the code for the previous example would look something like this:

```javascript
function login () {
  // show login form
  if (loginSuccessful) main()
}

function main () {
  // show user-only page
}

if (loggedIn) {
  main()
} else {
  login()
}
```

`roadblock` is intended to make your code more compact, more sequential, and less cluttered with named functions that are used only once or twice.

---
_Source: https://npm.io/package/roadblock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
