@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'}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.50latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i @ajoelp/express-validator

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

17.7 kB

Total Files

28

Last publish

Collaborators

  • ajoelp