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

base-form-schema

v1.0.0

Published

A TypeScript-first form management library designed to work seamlessly with Valtio and Zod.

Readme

FormSchema

A TypeScript-first form management library designed to work seamlessly with Valtio and Zod. Built as a lightweight alternative to React Hook Form, focusing on schema validation and state management.

Features

  • 🎯 Built for Valtio - Optimized for proxy-based state management
  • 📝 Zod Schema Integration - Type-safe form validation
  • 🔄 Multiple Validation Modes - onChange, onBlur, or onSubmit
  • 💪 TypeScript-first - Full type safety and excellent DX
  • 🪶 Lightweight - Zero dependencies beyond Valtio and Zod

Installation

npm install form-schema valtio zod
# or
yarn add form-schema valtio zod

Quick Start

import { proxy } from 'valtio';
import { z } from 'zod';
import { BaseForm } from 'form-schema';

// Define your schema
const schema = z.object({
  firstName: z.string().min(2),
  lastName: z.string().min(2),
  email: z.string().email(),
  password: z.string().min(8)
});

// Create your form class
class LoginForm extends BaseForm<typeof schema> {
  get fullName(): string {
    return `${this.data.firstName} ${this.data.lastName}`.trim();
  }
}

// Create your form state
const formState = proxy(new LoginForm(schema));

// Use in your component
function LoginComponent() {
  const form = useSnapshot(formState);

  const handleSubmit = (e: FormEvent) => {
    e.preventDefault();
    const data = form.validate();
    if (data) {
      // Valid form data
      console.log(data);
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <input
        value={form.data.firstName}
        onChange={e => form.setValue('firstName', e.target.value)}
        onBlur={() => form.handleBlur('firstName')}
        placeholder="First Name"
      />
      {form.errors.firstName?.map(error => (
        <span key={error}>{error}</span>
      ))}

      <input
        value={form.data.lastName}
        onChange={e => form.setValue('lastName', e.target.value)}
        onBlur={() => form.handleBlur('lastName')}
        placeholder="Last Name"
      />
      {form.errors.lastName?.map(error => (
        <span key={error}>{error}</span>
      ))}

      <input
        value={form.data.email}
        onChange={e => form.setValue('email', e.target.value)}
        onBlur={() => form.handleBlur('email')}
        placeholder="Email"
      />
      {form.errors.email?.map(error => (
        <span key={error}>{error}</span>
      ))}

      <div>Full Name: {form.fullName}</div>
      {/* ... */}
    </form>
  );
}

Advanced Usage

Custom Validation with Zod Effects

const schema = z.effect(
  z.object({
    username: z.string()
  })
)
.superRefine((data, ctx) => {
  if (data.username.includes('admin')) {
    ctx.addIssue({
      code: z.ZodIssueCode.custom,
      message: "Username cannot contain 'admin'"
    });
  }
})
.transform(data => ({
  ...data,
  displayName: `@${data.username}`
}));

Different Validation Modes

// Validate on input change
const form = new LoginForm(schema, {}, { validationMode: 'onChange' });

// Validate on field blur
const form = new LoginForm(schema, {}, { validationMode: 'onBlur' });

// Validate only on submit (default)
const form = new LoginForm(schema, {}, { validationMode: 'onSubmit' });

Form State Management

// Check if form is dirty
console.log(form.isDirty);

// Check if specific field is dirty
console.log(form.isFieldDirty('email'));

// Reset form to initial values
form.reset();

// Clear form
form.clear();

// Set custom error
form.setError('email', 'Email already exists');