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

@forgehive/schema

v0.1.4

Published

A powerful schema validation library built on top of Zod, providing type-safe validation and type inference.

Downloads

23

Readme

@forgehive/schema

A powerful schema validation library built on top of Zod, providing type-safe validation and type inference.

Installation

npm install @forgehive/schema

Overview

The @forgehive/schema package provides a wrapper around Zod with additional features:

  • Type-safe schema definitions
  • Built-in validation methods
  • Schema description capabilities
  • Type inference utilities

Basic Usage

Here's a simple example of creating and using a schema:

import { Schema } from '@forgehive/schema';

// Create a schema with validation
const userSchema = new Schema({
  name: Schema.string(),
  age: Schema.number().min(0).max(120),
  email: Schema.string().email(),
  tags: Schema.array(Schema.string())
});

// Validate data
const result = userSchema.safeParse({
  name: 'John Doe',
  age: 30,
  email: '[email protected]',
  tags: ['user', 'active']
});

if (result.success) {
  // TypeScript knows the shape of the data
  const user = result.data;
  console.log(user.name); // TypeScript knows this is a string
}

Schema Types

The package provides several schema types:

// Basic types
Schema.string()
Schema.number()
Schema.boolean()
Schema.date()

// Arrays
Schema.array(Schema.string())
Schema.array(Schema.number())
Schema.array(Schema.boolean())
Schema.array(Schema.date())

// Records
Schema.stringRecord()  // Record<string, string>
Schema.numberRecord()  // Record<string, number>
Schema.booleanRecord() // Record<string, boolean>
Schema.mixedRecord()   // Record<string, string | number | boolean>

Validation

Schemas provide several validation methods:

const schema = new Schema({
  name: Schema.string(),
  age: Schema.number()
});

// Parse and throw on error
const data = schema.parse({ name: 'John', age: 30 });

// Safe parse with result object
const result = schema.safeParse({ name: 'John', age: 30 });
if (result.success) {
  const data = result.data;
} else {
  const errors = result.error;
}

// Validate without parsing
const isValid = schema.validate({ name: 'John', age: 30 });

Schema Description

You can get a description of the schema structure:

const schema = new Schema({
  name: Schema.string(),
  age: Schema.number().min(0),
  email: Schema.string().email()
});

const description = schema.describe();
// Returns:
// {
//   name: { type: 'string' },
//   age: { type: 'number', validations: { min: 0 } },
//   email: { type: 'string', validations: { email: true } }
// }

Type Inference

The package provides type utilities for inferring types from schemas:

import { Schema, type InferSchema } from '@forgehive/schema';

const schema = new Schema({
  name: Schema.string(),
  age: Schema.number()
});

// Infer the type from the schema
type User = InferSchema<typeof schema>;
// Type is: { name: string; age: number }

API Reference

Schema Class

  • constructor(fields: Record<string, SchemaType>): Creates a new schema
  • parse(data: unknown): Parses and validates data, throws on error
  • safeParse(data: unknown): Safely parses and validates data
  • validate(data: unknown): Validates data without parsing
  • describe(): Returns a description of the schema structure
  • asZod(): Returns the underlying Zod schema

Static Methods

  • string(): Creates a string schema
  • number(): Creates a number schema
  • boolean(): Creates a boolean schema
  • date(): Creates a date schema
  • array(type): Creates an array schema
  • stringRecord(): Creates a record schema with string values
  • numberRecord(): Creates a record schema with number values
  • booleanRecord(): Creates a record schema with boolean values
  • mixedRecord(): Creates a record schema with mixed values

License

MIT