Neatly Positioned Magazines

    afraid
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0-alpha.11 • Public • Published

    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.

    Keywords

    none

    Install

    npm i afraid

    DownloadsWeekly Downloads

    1

    Version

    1.0.0-alpha.11

    License

    ISC

    Unpacked Size

    81.7 kB

    Total Files

    62

    Last publish

    Collaborators

    • robinbuschmann