Fortify Schema: A Revolutionary TypeScript-First Schema Validation Library
If you're a TypeScript developer tired of verbose, complex schema validation libraries that don't fully leverage TypeScript's power, you need to check out Fortify Schema — a revolutionary schema validation library that brings TypeScript interface syntax to runtime validation.
Why Fortify Schema?
Traditional libraries like Zod, Joi, or Yup often require cumbersome APIs and manual type definitions. Fortify Schema changes the game by allowing you to write schemas that look exactly like TypeScript interfaces — intuitive, clean, and type-safe.
Key Features
- Interface-like syntax that TypeScript developers instantly understand
- Perfect type inference with no manual typings needed
- Compile-time safety that prevents invalid properties before runtime
- Exact union and constant types instead of generic unions
- Intuitive constraint syntax with function-like parameters
- Zero learning curve if you know TypeScript
Example
import { Interface, Make } from 'fortify-schema';
const UserSchema = Interface({
id: "number",
email: "email",
name: "string(2,50)", // String length constraints
age: "number(18,120)?", // Optional number with range
tags: "string[](1,10)?", // Optional array with size constraints
status: Make.union("active", "inactive"),
role: Make.const("admin")
});
const result = UserSchema.safeParse(userData);
if (result.success) {
// result.data is perfectly typed with exact union and literal types
console.log('Valid user:', result.data);
} else {
console.log('Validation errors:', result.errors);
}
Schema Transformation Made Easy
Fortify Schema also includes powerful utilities for schema transformation such as Mod.partial()
, Mod.omit()
, Mod.extend()
, and more, allowing you to create variations of your schemas effortlessly.
Installation
npm install fortify-schema
Requirements: TypeScript 4.5+ and Node.js 14+
Fortify Schema is designed to make your TypeScript validation code cleaner, safer, and more maintainable. Give it a try and experience a zero learning curve schema validation library that feels just like writing TypeScript interfaces!
Check it out on GitHub: Nehonix-Team/fortify-schema
If you've published on Dev.to, read this: Dev.to is distributing free tokens as a thank-you for your contributions. Visit the claim page here. for verified Dev.to users only. – Dev.to Airdrop Desk