SCHEMA
Introduction

Schema - Introduction

Schema is a module of VkrunJS designed for runtime data validation. It provides a comprehensive set of tools to validate and structure data in JavaScript and TypeScript projects. With Schema, you can define simple or complex validation rules to ensure the integrity of your application's data.

Schemas are created by chaining validation methods, making it intuitive to define and manage data validation logic. Schema offers a robust, customizable, and scalable solution for your validation needs.

Quick Start

The following example demonstrates a simple schema for validating a user object:

import { schema } from "vkrun"
 
const userSchema = schema().object({
  id: schema().string().UUID(),
  fullName: schema().string().minWord(2),
  email: schema().string().email()
})
 
// Validates the data against the schema
const isValid = userSchema.validate({
  id: "3ef7c105-c4ea-444d-bf47-e2e1a49ea613",
  fullName: "John Doe",
  email: "john.doe@example.com"
})
 
console.log(isValid) // true
Copyright © 2024 MIT by Mario Elvio