8 downloads 163 views Apr 28, 2025
profile

Zood by Fabra

Updated Apr 28, 2025
project thumbnail

Welcome to Zood

Zood is a Lua library for ComputerCraft that provides a powerful and flexible way to validate and transform data structures. Inspired by Zod for TypeScript, Zood brings type safety and schema validation to Lua, making it easier to handle complex data in your ComputerCraft programs.


Features

  • Type Validation: Ensure data matches expected types (e.g., strings, numbers, tables).
  • Custom Validators: Add custom validation logic to suit your needs.
  • Data Transformation: Transform data as it is validated (e.g., trim strings, convert case).
  • Error Handling: Detailed error messages for debugging and validation failures.
  • Schema Composition: Combine schemas to create complex validation rules.

Quick Start

Here’s a quick example of how to use Zood to validate a table:

local Z = require("z")

local schema = Z.table({
  name = Z.string(),
  age = Z.number():positive(),
  email = Z.string():email()
})

local data = {
  name = "Alice",
  age = 30,
  email = "[email protected]"
}

local ok, result = schema:safeParse(value)
if not ok then
  -- result is a ValidationError object
  print(result:format())         -- Formatted error string (all errors, nicely formatted)
  for _, err in ipairs(result.errors) do
    print(err.message)           -- Each error message (raw)
    -- err is a table with fields: message, code, path, value, expected, received, details
  end
end
wget run https://pinestore.cc/d/135
Git Repository
comments
You can login with Discord to leave comments and reply to others!
pfp Fatboychummy 1 month ago

url schema does not allow direct IPs or localhost!

http://localhost -> Valid!

http://127.0.0.1 -> Valid!

pfp Fabra Creator 1 month ago

thanks for catching that.. I've updated the URL schema now