# afraid

> Express middlewares for validating incoming data with type inference

Latest version **1.0.0-alpha.11** (published 2019-01-08) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.11 |
| Published | 2019-01-08 |
| First published | 2018-11-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 79.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Robin Baum |
| Maintainers | robinbuschmann |

## Links

- npm: https://www.npmjs.com/package/afraid
- Repository: https://github.com/RobinBuschmann/afraid
- Homepage: https://github.com/RobinBuschmann/afraid#readme
- Issues: https://github.com/RobinBuschmann/afraid/issues
- npm.io page: https://npm.io/package/afraid

## Dependencies (2)

- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.12
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.1.9

## Recent versions

- 1.0.0-alpha.11 (latest) — 2019-01-08
- 1.0.0-alpha.10 — 2018-12-18
- 1.0.0-alpha.9 — 2018-12-12
- 1.0.0-alpha.8 — 2018-12-07
- 1.0.0-alpha.7 — 2018-12-07
- 1.0.0-alpha.6 — 2018-12-07
- 1.0.0-alpha.5 — 2018-11-17
- 1.0.0-alpha.4 — 2018-11-17
- 1.0.0-alpha.3 — 2018-11-17
- 1.0.0-alpha.2 — 2018-11-17
- 1.0.0-alpha.0 — 2018-11-17

## README

[![NPM](https://img.shields.io/npm/v/afraid.svg)](https://www.npmjs.com/package/afraid)
[![Build Status](https://travis-ci.org/RobinBuschmann/afraid.svg?branch=master)](https://travis-ci.org/RobinBuschmann/afraid)

# afraid
> 😧 Afraid?! You don't need to be: Incoming data  of your express route is validated!
Type inference included!

![](https://github.com/RobinBuschmann/afraid/raw/master/demos/demo.gif)

 - [Installation](#installation)
 - [Usage](#usage)
 - [Usage with classes](#using-classes-for-validation-and-transformation)
 - [Generating swagger documentation](#swagger-documentation)

## Installation
```bash
npm install afraid --save --no-optional
```

## Usage
```typescript
import {query, f, fail} from 'afraid';
import * as express from 'express';

const app = express();

app.get('/users', [
    query(
        f('limit').int(),
        f('offset').int(),
        f('filters').string().array().opt(),
    ),
    fail,
], (req, res, next) => {
    // ...
});
```

## Using classes for validation and transformation

#### Installation
Omitting `--no-optional` will install required packages `class-transformer` and `reflect-metadata` automatically
```
npm install afraid --save 
```
#### Configuration
The following flags in `tsconfig.json`:
```json
{
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true
}
```

#### Usage
```typescript
import {query, Field, IsInt, fail} from 'afraid'
import * as express from 'express';

const app = express();

class UserDTO {
    @Field name: string;
    @IsInt() @Field age: number;
}

app.post('/users', [
    body(UserDTO),
    fail,
], (req, res, next) => {
    // ...
});
```

## Swagger documentation
Use [afraid-swagger](https://github.com/RobinBuschmann/afraid-swagger) to create swagger documentation from afraid 
middlewares.

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