Socket
Socket
Sign inDemoInstall

afraid

Package Overview
Dependencies
16
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    afraid

Express middlewares for validating incoming data with type inference


Version published
Weekly downloads
11
Maintainers
1
Install size
759 kB
Created
Weekly downloads
 

Readme

Source

NPM Build Status

afraid

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

Installation

npm install afraid --save --no-optional

Usage

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:

{
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true
}
Usage
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 to create swagger documentation from afraid middlewares.

FAQs

Last updated on 08 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc