0.2.0 ā€¢ Published 2 years ago

enkyro v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Welcome to Enkyro šŸ‘‹

Version License: MIT

A simple but powerful middleware to validate request object in express

Code Example

import { validateRequestBody, Validators } from 'enkyro';
import express from 'express';

const app = express();

app.get("/", validateRequestBody([
    {
        key: "username",
        validator: Validators.rangeChar(5, 10),
        response: {
            message: "Username must be between 5-10 characters."
        }
    },
    {
        key: "password",
        validator: [Validators.minChar(8), Validators.regex(/regex/)]
    }
]), (req, res) => {
    res.send("Successfully validated!");
})

 

Validationable interface

type ValidationableResponse = CustomResponseOption | CustomResponseFunction;

type ValidatorFunction<T> = (test: T) => boolean;

type ValidationableValidator<T> = ValidatorFunction<T> | ValidatorFunction<T>[];


interface Validationable<T> {
    key: string;
    validator:  ValidationableValidator<T>;
    response?: ValidationableResponse;
}

Author

šŸ‘¤ Rich

Show your support

Give a ā­ļø if this project helped you!


This README was generated with ā¤ļø by readme-md-generator