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

0.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i enkyro

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

36.9 kB

Total Files

35

Last publish

Collaborators

  • __rich__