npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-fast-validate

v0.1.0

Published

A lightweight, fast, and tree-shakable validation library focused on performance and developer experience. Alternative to Zod/Yup for JSON, API responses, and form validation.

Readme

ts-fast-validate

A lightweight, fast, and tree-shakable validation library focused on performance and developer experience. Alternative to Zod/Yup for JSON, API responses, and form validation.

🚀 Features

  • Lightning Fast: Optimized for performance with minimal overhead
  • Tree-shakable: Import only what you need
  • TypeScript First: Full type safety and inference
  • Small Bundle Size: Minimal impact on your bundle
  • Familiar API: Easy migration from Zod/Yup
  • Zero Dependencies: No external dependencies

📦 Installation

npm install ts-fast-validate
# or
yarn add ts-fast-validate
# or
pnpm add ts-fast-validate

🔧 Basic Usage

import { string, number, boolean, object, array, email } from 'ts-fast-validate';

// Define a schema
const userSchema = object({
  name: string(),
  email: email(),
  age: number(),
  isActive: boolean(),
  tags: array(string()).optional()
});

// Validate data (throws on error)
const user = userSchema.parse({
  name: 'John Doe',
  email: '[email protected]',
  age: 25,
  isActive: true
});

// Safe validation (returns result object)
const result = userSchema.safeParse(userData);
if (result.success) {
  console.log(result.data); // Typed data
} else {
  console.log(result.error); // Validation error with path
}

📚 API Reference

Basic Types

import { string, number, boolean, literal } from 'ts-fast-validate';

const nameSchema = string();
const ageSchema = number();
const isActiveSchema = boolean();
const roleSchema = literal('admin'); // Only accepts 'admin'

String Validators

import { string, email, url, uuid, stringMin, stringMax, length, regex } from 'ts-fast-validate';

const emailSchema = email();
const urlSchema = url();
const uuidSchema = uuid();
const minLengthSchema = stringMin(3)(string());
const maxLengthSchema = stringMax(50)(string());
const exactLengthSchema = length(10)(string());
const regexSchema = regex(/^[A-Z]+$/)(string());

Number Validators

import { number, int, positive, negative, nonnegative, numberMin, numberMax, finite } from 'ts-fast-validate';

const integerSchema = int();
const positiveSchema = positive();
const negativeSchema = negative();
const nonNegativeSchema = nonnegative();
const minSchema = numberMin(0)(number());
const maxSchema = numberMax(100)(number());
const finiteSchema = finite();

Complex Types

import { object, array, union, record } from 'ts-fast-validate';

// Objects
const userSchema = object({
  id: number(),
  name: string(),
  email: email()
});

// Arrays
const numbersSchema = array(number());
const usersSchema = array(userSchema);

// Unions
const statusSchema = union(
  literal('pending'),
  literal('approved'),
  literal('rejected')
);

// Records (key-value maps)
const metadataSchema = record(string());

Schema Modifiers

// Optional fields
const optionalSchema = string().optional(); // string | undefined

// Nullable fields  
const nullableSchema = string().nullable(); // string | null

// Default values
const defaultSchema = string().default('hello');

// Custom validation
const customSchema = string().refine(
  (value): value is string => value.length > 5,
  'Must be longer than 5 characters'
);

// Transform values
const upperSchema = string().transform(s => s.toUpperCase());

// Chaining
const complexSchema = string()
  .optional()
  .default('default')
  .transform(s => s.toUpperCase());

🎯 Real-world Examples

API Response Validation

import { object, array, number, string, boolean } from 'ts-fast-validate';

const apiResponseSchema = object({
  success: boolean(),
  data: array(object({
    id: number(),
    title: string(),
    published: boolean(),
    author: object({
      name: string(),
      email: email()
    })
  })),
  pagination: object({
    page: number(),
    limit: number(),
    total: number()
  })
});

// Use with fetch
const response = await fetch('/api/posts');
const json = await response.json();
const validatedData = apiResponseSchema.parse(json);

Form Validation

import { object, string, email, stringMin } from 'ts-fast-validate';

const signupFormSchema = object({
  username: stringMin(3)(string()),
  email: email(),
  password: stringMin(8)(string()),
  confirmPassword: string()
}).refine(
  (data): data is typeof data => data.password === data.confirmPassword,
  'Passwords must match'
);

function handleFormSubmit(formData: FormData) {
  const result = signupFormSchema.safeParse({
    username: formData.get('username'),
    email: formData.get('email'),
    password: formData.get('password'),
    confirmPassword: formData.get('confirmPassword')
  });

  if (!result.success) {
    console.error('Validation errors:', result.error);
    return;
  }

  // Form data is now validated and typed
  console.log('Valid form data:', result.data);
}

⚡ Performance

ts-fast-validate is designed for speed:

  • Fast validation: Optimized validation logic with minimal overhead
  • Tree-shakable: Bundle only the validators you use
  • Zero dependencies: No external dependency overhead
  • Small footprint: Minimal impact on bundle size

🔄 Migration from Zod

ts-fast-validate has a similar API to Zod, making migration straightforward:

// Zod
import { z } from 'zod';
const schema = z.object({
  name: z.string(),
  age: z.number().positive()
});

// ts-fast-validate
import { object, string, positive } from 'ts-fast-validate';
const schema = object({
  name: string(),
  age: positive()
});

📄 License

MIT

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.