@ajoelp/express-validator
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.5 • Public • Published

    Express Validator

    Installation

    ## npm
    npm i @ajoelp/express-validator
    
    ## yarn
    yarn add @ajoelp/express-validator

    Usage

    import express from 'express';
    import {body, query, params, validationResponseMiddleware} from '@ajoelp/express-validator'
    
    const app = express();
    
    app.get(
        '/',
        [
            query({
                'search': ['required', 'string'],
            }),
            params({
                'userId': ['required', 'number'],
            }),
            body({
                'email': ['required', 'email'],
                'password': ['required', { type: 'string', message: 'This needs to be a string'}],
            }),
            validationResponseMiddleware,
            (req, res) => res.send()
        ]
    )
    
    // express app setup...

    Rules

    Rule Rule String Rule Object
    RequiredRule required { type: 'required', message: 'This is the message'}
    StringRule string { type: 'string', message: 'This is the message'}
    NumberRule number { type: 'number', message: 'This is the message'}
    MinRule { type: 'min', value: 3, message: 'This is the message'}
    MaxRule { type: 'max', value: 4, message: 'This is the message'}
    BooleanRule boolean { type: 'boolean', message: 'This is the message'}
    EmailRule email { type: 'email', regex: new RegExp(), message: 'This is the message'}
    DateRule date { type: 'date', message: 'This is the message'}
    NullableRule nullable
    CustomRule { type: 'custom', rule: (value: string, request: Request) => Promise<boolean>, message: 'This is the message'}

    Install

    npm i @ajoelp/express-validator

    DownloadsWeekly Downloads

    2

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    17.7 kB

    Total Files

    28

    Last publish

    Collaborators

    • ajoelp