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

@ambrosia-unce/validator

v1.0.3

Published

Type-safe compile-time validation for Ambrosia framework

Readme

@ambrosia-unce/validator

Type-safe compile-time validation for Ambrosia framework using Bun plugin system and TypeScript Compiler API.

Features

  • Zero runtime overhead - Validation code generated at compile-time
  • Type-safe - Full TypeScript type inference
  • No decorators - Just TypeScript types
  • No schema duplication - Types are the schema
  • Branded types - Email, UUID, PositiveInt, and more
  • JSDoc constraints - @minLength, @pattern, etc.
  • Bun native - Uses Bun plugin system

Installation

bun add @ambrosia-unce/validator

Setup

Add to your bunfig.toml:

preload = ["@ambrosia-unce/validator/preload"]

That's it! The plugin is now active.

Usage

Basic validation

import { validate, assert, is } from '@ambrosia-unce/validator';

interface User {
  name: string;
  email: string;
  age: number;
}

// validate<T>() - Returns result object
const result = validate<User>(data);
if (result.success) {
  console.log(result.data.name);
} else {
  console.error(result.errors);
}

// assert<T>() - Throws on error
try {
  const user = assert<User>(data);
  console.log(user.name);
} catch (error) {
  console.error(error);
}

// is<T>() - Type guard
if (is<User>(data)) {
  // data is User here
  console.log(data.name);
}

Branded types

import type { Email, UUID, PositiveInt } from '@ambrosia-unce/validator/types';

interface User {
  id: UUID;
  email: Email;
  age: PositiveInt;
  name: string;
}

const user = assert<User>({
  id: "550e8400-e29b-41d4-a716-446655440000",
  email: "[email protected]",
  age: 25,
  name: "Alice"
});

Available branded types:

  • Email - RFC 5322 email
  • UUID - UUID v4
  • URL - Valid HTTP/HTTPS URL
  • PositiveInt - Integer > 0
  • NonNegativeInt - Integer >= 0
  • DateString - ISO 8601 date
  • DateTime - ISO 8601 datetime
  • PhoneNumber - E.164 format
  • IPv4, IPv6 - IP addresses
  • HexColor - #RRGGBB or #RGB
  • And more...

JSDoc constraints

interface UpdateUserDto {
  /**
   * @minLength 3
   * @maxLength 50
   * @pattern ^[a-zA-Z0-9_]+$
   */
  name?: string;

  /**
   * @format email
   */
  email?: string;

  /**
   * @minimum 18
   * @maximum 120
   */
  age?: number;
}

const dto = assert<UpdateUserDto>(data);

With Ambrosia HTTP

import { Controller, Post, Body } from '@ambrosia-unce/http';
import { assert } from '@ambrosia-unce/validator';

interface CreateUserDto {
  name: string;
  email: string;
}

@Controller('/users')
export class UserController {
  @Post('/')
  async create(@Body() data: unknown) {
    const dto = assert<CreateUserDto>(data);
    // dto is validated and typed!
    return this.userService.create(dto);
  }
}

How it works

The plugin uses TypeScript Compiler API to:

  1. Find all validate<T>(), assert<T>(), is<T>() calls
  2. Analyze the type T using TypeScript's type checker
  3. Generate optimized inline validation code
  4. Replace the function call with generated code

Before transformation:

const user = assert<User>(data);

After transformation:

const user = ((data) => {
  if (typeof data !== "object" || data === null)
    throw new ValidationError("must be an object");
  if (typeof data.name !== "string")
    throw new ValidationError("name must be string");
  if (typeof data.email !== "string")
    throw new ValidationError("email must be string");
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email))
    throw new ValidationError("email must be valid");
  if (typeof data.age !== "number")
    throw new ValidationError("age must be number");
  return data;
})(data);

Configuration

Custom plugin options:

// validator-config.ts
import { plugin } from "bun";
import { createValidatorPlugin } from "@ambrosia-unce/validator/plugin";

plugin(createValidatorPlugin({
  debug: true, // Enable debug logging
  include: /\.ts$/, // File patterns to include
  exclude: /node_modules/, // File patterns to exclude
}));

Then in bunfig.toml:

preload = ["./validator-config.ts"]

License

MIT