Skip to content

niceWizzard/enkyro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

'Enkyro', a latin word meaning, valid. A quick and easy middleware to validate requests in expressjs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published