Skip to content
Typyn Logo

Typyn Documentation

๐Ÿš€ Lightweight, Chainable TypeScript Validation
Validate data with speed and confidence โ€” zero dependencies, full type inference.

npm versionnpm downloadsbundle sizelicenseGitHub stars

Introduction โ€‹

Typyn is a minimalist validation library designed for TypeScript developers who need fast, intuitive schema building without the bloat. Drawing inspiration from tools like Zod and Yup, but stripped down for performance (up to 10M+ ops/sec on primitives), Typyn lets you chain rules fluently while ensuring runtime safety and compile-time types.

๐Ÿš€ Quick Start โ€‹

Installation โ€‹

Install Typyn using your preferred package manager:

bash
# Using pnpm (recommended)
pnpm add typyn

# npm
npm install typyn

# yarn
yarn add typyn

# bun
bun add typyn

Basic Usage โ€‹

Create a simple schema with the v factory:

ts
import { v } from "typyn";

// Define a schema
const userSchema = v.object({
  name: v.string().min(2).max(50),
  age: v.number().min(18).default(18),
  email: v.string().email().optional(),
});

// Validate input (throws on error)
const user = userSchema.parse({ name: "Alice", age: 22 });
console.log(user);
// โ†’ { name: "Alice", age: 22 }

// Safe validation (no throws)
const result = userSchema.safe({ name: "A", age: 10 });
if (!result.success) {
  console.error(result.error.message);
  // โ†’ "name โ†’ Must be at least 2 characters"
}

๐Ÿงฉ Extra Features โ€‹

Typyn schemas are chainable, type-safe, and composable:

ts
// Add transforms or defaults
const emailSchema = v.string().email().trim().transform(e => e.toLowerCase());

// Use refinements for custom logic
const even = v.number().refine(n => n % 2 === 0, "Must be even");

// Combine schemas
const config = v.object({
  port: v.number().min(1000).max(9999),
  secure: v.boolean().default(false),
});

โœ… .parse() โ€” strict mode (throws on failure). โœ… .safe() โ€” safe mode (returns { success, data?, error? }). โœ… .default() โ€” provides fallback values. โœ… .transform() โ€” modify output post-validation.


๐Ÿ”— Next Steps โ€‹

  1. Learn the Primitives โ†’
  2. Build Composite Schemas โ†’
  3. Handle Special Types โ†’
  4. See Real Examples โ†’

MIT Licensed | Copyright ยฉ 2025 ManojKumar2920