class-validator

Decorator-based property validation for TypeScript and JavaScript classes, on both Node.js and the browser.

Library
npm
v0.15.1
11,847 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 4
Maintenance 20
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 85
Code Quality 85
Innovation 90
Learning Curve 80

class-validator lets you attach validation rules directly to class properties using TypeScript decorators such as @IsEmail, @Length, and @Min, then validate instances with a single call. It ships more than a hundred built-in constraint decorators and, internally, delegates string checks to the battle-tested validator.js library.

Beyond simple property checks it supports nested-object validation, conditional rules, validation groups, custom decorators, whitelisting of unknown properties, and both asynchronous and synchronous validation. It works the same way in the browser and in Node.js, and integrates cleanly with frameworks like NestJS and dependency-injection containers.

What You Get

  • 100+ ready-made constraint decorators covering strings, numbers, dates, arrays, sets, maps, and common formats (email, URL, UUID, phone, and more)
  • Structured ValidationError results that report the target, property, offending value, and per-constraint messages, including nested children
  • Advanced validation features: nested objects, validation groups, conditional validation, whitelisting, and custom validators and decorators
  • Both async (validate/validateOrReject) and sync (validateSync) APIs that run identically in Node.js and the browser

Common Use Cases

  • Validating incoming request DTOs in a NestJS or Express API before they reach business logic
  • Enforcing shape and format on user-submitted form data on the client side
  • Guarding configuration or message payloads against malformed values in shared browser/Node code

Under The Hood

Architecture

The public surface in src/index.ts exposes thin validate/validateOrReject/validateSync helpers that instantiate a Validator and delegate to a ValidationExecutor (src/validation/ValidationExecutor.ts). Decorators register constraint metadata into a global MetadataStorage (src/metadata/MetadataStorage.ts) at class-definition time; at validation time the executor reads that metadata, resolves each constraint through an IoC container (src/container.ts, overridable via useContainer for DI frameworks), runs the constraints, collects async work into an awaitingPromises list, and builds nested ValidationError trees. This metadata-plus-executor split cleanly separates declaration from execution.

Tech Stack

Written almost entirely in TypeScript (99.8% of the source). Runtime dependencies are minimal: validator.js for the underlying string checks and libphonenumber-js for phone validation. It builds to CommonJS, ESM5, ES2015, and UMD bundles via tsc and Rollup, so it consumes cleanly in bundlers and Node alike. reflect-metadata is used for decorator metadata.

Code Quality

The repo has a substantial test suite: 15 spec files including a large functional test directory (validation-functions-and-decorators, whitelist-validation, custom-decorators, promise-validation, inherited-validation, sync-validation) run under Jest with coverage. Code is consistently typed, ESLint- and Prettier-enforced, and organized by decorator family under src/decorator/. Nine runnable samples document real usage patterns.

API Design The developer experience is a core strength: decorators read almost like documentation on the property they guard, getting started needs only an import and an annotation, and the 100+ decorators follow a consistent Is*/@Min/@Max naming scheme. The README is extensive, covering options, custom decorators, groups, and framework integration, making the learning curve gentle for the common cases.

Used by 23 apps in this directory

TypeScript
81%
AGPL 3.0

Postiz

Automation · Social Media

37,683

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
92
Repo Health
70
Technical
63
Dependency
Built with
TypeScript 81%
JavaScript 11%
Updated 6 days ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,213

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 6 days ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 5 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers