# flow-guard

> Flow Guard is a babel macro that adds a runtime guard for your flow types. This macro generates [decoders](https://nvie.com/posts/introducing-decoders/) based on your flow types and throws a runtime error if the unsafe data does not match. It is useful to

Latest version **0.97.0** (published 2019-04-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install flow-guard
pnpm add flow-guard
yarn add flow-guard
bun add flow-guard
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.97.0 |
| Published | 2019-04-17 |
| First published | 2018-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Steve Farthing |
| Maintainers | simple-contacts-engineering |

## Links

- npm: https://www.npmjs.com/package/flow-guard
- npm.io page: https://npm.io/package/flow-guard

## Dependencies (5)

- [decoders](https://npm.io/package/decoders.md) ^1.11.1
- [flow-bin](https://npm.io/package/flow-bin.md) ^0.97.0
- [prettier](https://npm.io/package/prettier.md) ^1.14.3
- [babel-plugin-macros](https://npm.io/package/babel-plugin-macros.md) ^2.4.2
- [@babel/plugin-syntax-flow](https://npm.io/package/@babel/plugin-syntax-flow.md) ^7.0.0

## Recent versions

- 0.97.0 (latest) — 2019-04-17
- 0.85.0 — 2019-04-11
- 0.84.0 — 2019-02-26
- 0.83.0 — 2019-01-23
- 0.82.0 — 2019-01-22
- 0.81.0 — 2018-10-04

## README

# Flow Guard

Flow Guard is a babel macro that adds a runtime guard for your flow types. This macro generates [decoders](https://nvie.com/posts/introducing-decoders/) based on your flow types and throws a runtime error if the unsafe data does not match. It is useful to type-check the boundaries of your application for incoming unsafe data (See [decoders](https://nvie.com/posts/introducing-decoders/)).

## Example guard macro

```javascript
// @flow
import guard from 'flow-guard/macro';

type Point = { x: number, y: number };

function handlePost(someUnsafeData: any): Point {
  return guard<Point>(someUnsafeData);
}
```

## Example decoder macro

```javascript
// @flow
import createDecoder from 'flow-guard/decoder.macro';
import { guard } from 'decoders';

type Point = { x: number, y: number };

const pointDecoder = createDecoder<Point>();

function handlePost(someUnsafeData: any): Point {
  return guard(pointDecoder)(someUnsafeData);
}
```

## Installation

Requires babel 7.x

```
npm install --save-dev babel-plugin-macros
npm install --save-dev flow-guard
```

Edit .babelrc to include the macros plugin: 'macros'

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