# simple-guards

> Utils to add guard clauses to JS code

Latest version **1.0.0** (published 2017-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-guards
pnpm add simple-guards
yarn add simple-guards
bun add simple-guards
```

## 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.0.0 |
| Published | 2017-02-14 |
| First published | 2016-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Trabe |
| Maintainers | trabe |

## Links

- npm: https://www.npmjs.com/package/simple-guards
- Repository: https://github.com/trabe/simple-guards
- Homepage: https://github.com/trabe/simple-guards.git
- Issues: https://github.com/trabe/simple-guards/issues
- npm.io page: https://npm.io/package/simple-guards

## Recent versions

- 1.0.0 (latest) — 2017-02-14
- 0.0.1 — 2016-06-09

## README

# Simple Guards

## Description

Simple utilities to add guard clauses to yout JS code.

Guards raises an Error if a given condition is truthy.

## Features

* Guards not executed in production environment (`process.env.NODE_ENV !== "production"`)
* Guards can be checked lazily

## Install

```
npm instal simple-guards
````

## Usage

To set a simple guard:

```
import { guard } from "simple-guards";

function division(numerator, denominator) {
  guard(denominator === 0, "denominator cannot be zero");

  // more awful code
}
```

You can also pass a function to lazy evaluate an expensive guard:

```

function division(numerator, denominator) {
  guard(() => expensiveDetectionOfZero(denominator), "denominator cannot be zero");

  // more awful code
}

```

If you want to lazy evaluate many guards you can use the `guards` method to
avoid excessive wrapper functions:

```
import { guards } from "simple-guards";

function division(numerator, denominator) {
  guards((guard) => {
    guard(expensiveDetectionOfZero(numerator), "we don't want numerator to be zero");
    guard(expensiveDetectionOfZero(denominator), "denominator cannot be zero");
  })

  // more awful code
}

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