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

@youneed/schema

v0.1.0

Published

class-validator-style DTO validation on standard TC39 decorators (no reflect-metadata, works in JS).

Readme

@youneed/schema

class-validator-style DTO validation, but on standard TC39 decorators — no reflect-metadata, no emitDecoratorMetadata, no experimentalDecorators. The exact same decorated class runs in TypeScript and plain JS.

import { IsEmail, IsNotEmpty, MinLength, IsOptional, IsInt, Min, validate } from "@youneed/schema";

class CreateUserDTO {
  @IsEmail() email!: string;
  @IsNotEmpty() @MinLength(8) password!: string;
  @IsOptional() @IsInt() @Min(18) age?: number;
}

const errors = validate(CreateUserDTO, await req.json());
// [] when valid, else:
// [{ property: "email", value: "nope", constraints: { isEmail: "email must be an email" } }]

Validate

validate(CreateUserDTO, plainObject) // ValidationError[] (class + plain object)
validate(dtoInstance)                // ValidationError[] (an instance)
isValid(CreateUserDTO, plainObject)  // boolean
validateOrThrow(CreateUserDTO, body) // throws SchemaError (carries .errors)
plainToInstance(CreateUserDTO, body) // build an instance from a plain object

ValidationError mirrors class-validator: { property, value, constraints }, where constraints is { [ruleName]: message }.

Constraints

| decorator | passes when | | --- | --- | | @IsDefined() | not null/undefined | | @IsNotEmpty() | not null/undefined and not "" | | @IsOptional() | modifier — skip the field's other rules when it's null/undefined | | @IsString() · @IsNumber() · @IsInt() · @IsBoolean() · @IsArray() | type matches | | @IsEmail() · @IsUrl() | valid email / http(s) URL | | @MinLength(n) · @MaxLength(n) | string/array length in range | | @Min(n) · @Max(n) | number in range | | @Matches(/re/) | string matches the regexp | | @IsIn([...]) | value is one of the list | | @Custom(name, test) | your own predicate |

Every decorator takes an optional { message } to override the default text:

class LoginDTO {
  @IsNotEmpty({ message: "password is required" }) password!: string;
}

Compose freely — multiple decorators on one field all apply, and subclasses inherit their parent's constraints.

Why TC39 decorators

class-validator relies on reflect-metadata + the legacy experimental decorators (experimentalDecorators + emitDecoratorMetadata), which only exist under TypeScript. @youneed/schema uses the Stage-3 standard decorators that ship in modern engines and transpile without any metadata runtime — so a compiled-to-JS DTO validates identically.

Implementation note: TS/esbuild only attach Symbol.metadata to a class that also carries a class decorator, so a fields-only DTO would lose it. Each field decorator instead registers its rules via context.addInitializer into a constructor-keyed WeakMap; validate(Class, …) constructs one throwaway instance to trigger that, then checks your plain object.

Use it in a handler / guard

import { validateOrThrow } from "@youneed/schema";

app.post("/users", (ctx) => {
  validateOrThrow(CreateUserDTO, ctx.body); // throws SchemaError → map to 422
  // …ctx.body is now known-good
});