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.
119 lines (108 loc) • 3.95 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Examples - 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">📚 Examples</h1>
<p class="text-xl text-purple-100">Real-world usage patterns</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">⚙️ Mod</a>
<a href="examples.html" class="nav-link active">📚 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 text-gray-800 mb-6">Array of Objects</h2>
<pre class="code-block"><code class="language-typescript">import { Interface } from "fortify-schema";
const CourseSchema = Interface({
id: "string",
title: "string",
videos: [{
id: "string",
title: "string",
duration: "number",
url: "url.https"
}]
});
// Valid
const course = {
id: "course-1",
title: "TypeScript Mastery",
videos: [
{ id: "v1", title: "Intro", duration: 120, url: "https://example.com/v1.mp4" },
{ id: "v2", title: "Advanced", duration: 180, url: "https://example.com/v2.mp4" }
]
};</code></pre>
</div>
</section>
<section class="mb-12">
<div class="section-card">
<h2 class="text-3xl font-bold text-gray-800 mb-6">User Management</h2>
<pre class="code-block"><code class="language-typescript">const UserSchema = Interface({
id: "uuid",
email: "email",
name: "string(2,50)",
role: Make.union("admin", "user", "guest"),
profile: {
bio: "string?",
avatar: "url?",
social: {
twitter: "string?",
github: "string?"
}
},
createdAt: "date"
});</code></pre>
</div>
</section>
<section>
<div class="section-card">
<h2 class="text-3xl font-bold text-gray-800 mb-6">API Endpoint Validation</h2>
<pre class="code-block"><code class="language-typescript">// Create endpoint
const CreatePostSchema = Interface({
title: "string(1,200)",
content: "string(1,10000)",
tags: "string[]?",
published: "boolean?"
});
// Update endpoint (partial)
const UpdatePostSchema = Mod.partial(CreatePostSchema);
// Use in Express
app.post('/posts', (req, res) => {
const result = CreatePostSchema.safeParse(req.body);
if (!result.success) {
return res.status(400).json({ errors: result.errors });
}
// result.data is fully typed!
const post = result.data;
});</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>