MIT License
Oak middleware for parameter and body validator
As a router middleware
import { validatorMiddleware, ValidatorMiddlewareOptions } from "https://raw.githubusercontent.com/halvardssm/oak-middleware-validator/master/mod.ts"
import { RouterMiddleware } from "https://deno.land/x/oak/mod.ts";
const router = new Router();
const app = new Application();
const options: ValidatorMiddlewareOptions = {
validations: [
{ key: "a", validationOption: "string", isUrlParam: true },
{ key: "b", validationOption: "b", isOptional: true },
{ key: "c", validationOption: validateStringIn("b") },
{ key: "d", validationOption: validateIsNumber(0, 1) },
],
bodyRequired: true,
errorMessages: {
ERROR_NO_BODY: "Custom message"
}
}
router
.get("/bar", validatorMiddleware(options),...)
app.use(router.routes());
await app.listen(appOptions);
typeof
or a string to compare strings(
key: string, // The key
value: string | Uint8Array, // The value
validationError: ValidationErrorFn, // The validation error callback
errorMessages: ErrorMessagesT, // Exposes the error messages
options: ValidatorMiddlewareOptions // Exposes the options
) => void
validateStringInArray(...values: string[])
// Checks if the value is in the arrayvalidateIsNumber(min?: number, max?: number, radix?: number)
// Checks if the value is a number, and if min/max is given it compares them inclusivelyAll contributions are welcome, make sure to read the contributing guidelines.