PACKAGE · VALIDATION

class-validator

Decorator-based property validation for classes.

WEEKLY DOWNLOADS 18.0M
STARS 11.9K
FORKS 848
OPEN ISSUES 329
GZIP SIZE 105.8 kB
UNPACKED SIZE 5.3 MB
LAST UPDATED 9mo ago
DOWNLOAD TRENDS

class-validator downloads · last 12 months

Download trends for class-validator1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.014.8M29.5M44.3M59.0MNov 2025FebMayAugOct 2026
class-validator
ABOUT CLASS-VALIDATOR

class-validator validates class properties through decorators, allowing rules to live alongside the TypeScript class definitions they describe. It addresses the gap between declaring a class’s expected shape and checking whether actual values satisfy constraints, producing validation errors that an application can inspect and handle.

Its design centers on declarative, property-level validation rather than a separate collection of imperative checks. This suits TypeScript developers who want class instances to document their constraints and have validation metadata applied through decorators; it also means the approach depends on using classes and decorator-enabled tooling.

The typical pattern is to place validation decorators on class properties, create an instance, and call the validation API to obtain errors. This keeps constraints close to the fields they govern, while validation results can be used to report invalid input or stop later processing; applications remain responsible for deciding how those errors are presented.

The package fits workflows that receive data and map it to class instances before validating it, including TypeScript services and applications that use class-based request or model objects. Its decorator approach can be integrated into a project’s existing input-handling flow, but it does not, by itself, define an application’s transport, error response format, or data-conversion policy.

The supplied package details indicate a mature, frequently downloaded project: version 0.15.1, 4.6M weekly downloads, 11.8K GitHub stars, and 847 forks. Its listed gzip bundle size is 105.8 kB, while the unpacked size is 5.3 MB, so developers should account for the distribution footprint in environments where dependency size is important.

There are 320 open issues, and the package was last updated on 2026-03-25, so teams should review the project’s current maintenance and issue status before adopting it. Decorators also impose a specific programming model: applications based on plain objects, schemas, or non-TypeScript class structures may need an additional mapping step or a different validation approach.

WHEN TO USE
  • When validating TypeScript class instances at an input boundary, define property constraints with decorators and call the validation API before processing the instance.
  • When class definitions should document their own validation rules, keep each constraint next to the property it governs instead of maintaining a separate set of imperative checks.
  • When a service maps incoming data into class instances, validate those instances and use the returned errors to decide whether to accept or reject the input.
  • When class-based request or model objects already structure an application’s data flow, add decorator-based checks to those classes without changing the overall class-oriented pattern.
  • When validation feedback needs to be handled by application code, inspect validation errors and translate them into the relevant response or user-facing messages.
  • When comparing dependency footprints, use the listed 105.8 kB gzip bundle size and 5.3 MB unpacked size to assess fit for the target environment.
WHEN NOT TO USE
  • If your data remains as plain objects and should not be converted into classes, use a validation approach designed for object or schema inputs, or add an explicit conversion step before class-validator runs.
  • If your project does not enable or support decorators, avoid decorator-based property rules and use a validation pattern compatible with its compiler and runtime configuration.
  • If constraints need to be declared separately from TypeScript classes, choose a schema-oriented approach rather than attaching validation metadata to class properties.
  • If the application expects validation to define HTTP responses or transform incoming data automatically, implement those responsibilities separately or choose an integration that provides them as part of its workflow.
  • If a 105.8 kB gzip bundle or 5.3 MB unpacked dependency is unsuitable for your deployment target, compare a lighter validation approach against those listed package sizes before adding it.
  • If your adoption decision depends on current maintenance activity or unresolved issue trends, review the project’s status directly; the supplied figures list 320 open issues and a last-updated date of 2026-03-25.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 9
class-validator vs ajv ★ 14.9K · 535.1M/wk class-validator vs joi ★ 21.2K · 33.6M/wk class-validator vs ow ★ 3.9K · 2.6M/wk class-validator vs @sinclair/typebox ★ 15 · 166.1M/wk class-validator vs zod ★ 44.4K · 462.8M/wk class-validator vs fast-xml-parser ★ 3.1K · 114.6M/wk class-validator vs yup ★ 23.6K · 16.4M/wk class-validator vs valibot ★ 9.1K · 35.1M/wk class-validator vs superstruct ★ 7.1K · 9.8M/wk