enkyro
v0.2.0
Published
A simple but powerful way to validate request object in express
Downloads
2
Readme
Welcome to Enkyro 👋
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