UNPKG

fortify-schema

Version:

A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.

144 lines (126 loc) 5.54 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Mod Utility - Fortify Schema</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script> <link rel="stylesheet" href="styles.css"> </head> <body class="bg-gray-50"> <header class="gradient-bg text-white shadow-lg"> <div class="container mx-auto px-6 py-8"> <h1 class="text-4xl font-bold mb-2">⚙️ Mod Utility</h1> <p class="text-xl text-purple-100">Transform and manipulate schemas</p> </div> </header> <nav class="bg-white shadow-md sticky top-0 z-50"> <div class="container mx-auto px-6"> <div class="flex space-x-8 overflow-x-auto py-4"> <a href="index.html" class="nav-link">🏠 Home</a> <a href="bug-fixes.html" class="nav-link">🐛 Bug Fixes</a> <a href="make-utility.html" class="nav-link">🔧 Make</a> <a href="mod-utility.html" class="nav-link active">⚙️ Mod</a> <a href="examples.html" class="nav-link">📚 Examples</a> <a href="api-reference.html" class="nav-link">📖 API</a> </div> </div> </nav> <main class="container mx-auto px-6 py-12"> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-4">Overview</h2> <p class="text-gray-600">The <code>Mod</code> utility provides powerful methods for transforming and manipulating existing schemas.</p> </div> </section> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.partial()</h2> <p class="text-gray-600 mb-4">Make all fields optional</p> <pre class="code-block"><code class="language-typescript">const UserSchema = Interface({ id: "number", name: "string", email: "email" }); const PartialUser = Mod.partial(UserSchema); // All fields now optional</code></pre> </div> </section> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.pick()</h2> <p class="text-gray-600 mb-4">Select specific fields</p> <pre class="code-block"><code class="language-typescript">const UserSchema = Interface({ id: "number", name: "string", email: "email", password: "string" }); const PublicUser = Mod.pick(UserSchema, ["id", "name", "email"]); // Only id, name, email</code></pre> </div> </section> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.omit()</h2> <p class="text-gray-600 mb-4">Exclude specific fields</p> <pre class="code-block"><code class="language-typescript">const UserSchema = Interface({ id: "number", name: "string", email: "email", password: "string" }); const SafeUser = Mod.omit(UserSchema, ["password"]); // All fields except password</code></pre> </div> </section> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.merge()</h2> <p class="text-gray-600 mb-4">Combine multiple schemas</p> <pre class="code-block"><code class="language-typescript">const BaseSchema = Interface({ id: "number", name: "string" }); const ExtendedSchema = Interface({ email: "email", age: "number?" }); const MergedSchema = Mod.merge(BaseSchema, ExtendedSchema); // Contains all fields from both schemas</code></pre> </div> </section> <section class="mb-12"> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.strict()</h2> <p class="text-gray-600 mb-4">Reject additional properties</p> <pre class="code-block"><code class="language-typescript">const UserSchema = Interface({ id: "number", name: "string" }); const StrictUser = Mod.strict(UserSchema); // This will fail StrictUser.parse({ id: 1, name: "John", extra: "field" }); // Error: Unexpected properties: extra</code></pre> </div> </section> <section> <div class="section-card"> <h2 class="text-3xl font-bold mb-6">Mod.defaults()</h2> <p class="text-gray-600 mb-4">Set default values</p> <pre class="code-block"><code class="language-typescript">const ConfigSchema = Interface({ host: "string", port: "number?", timeout: "number?" }); const ConfigWithDefaults = Mod.defaults(ConfigSchema, { port: 3000, timeout: 5000 }); // Only need to provide host const config = ConfigWithDefaults.parse({ host: "localhost" }); // { host: "localhost", port: 3000, timeout: 5000 }</code></pre> </div> </section> </main> <footer class="bg-gray-800 text-white mt-16 py-8"> <div class="container mx-auto px-6 text-center"> <p class="mb-2">© 2025 Nehonix Team. All rights reserved.</p> </div> </footer> <script>hljs.highlightAll();</script> </body> </html>