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

@tgb-form/core

v0.0.4

Published

An easy to use form library, with powerful schema-based form definition capabilities.

Readme

@tgb-form/core

Portable form definitions for TanStack Form and Valibot.

@tgb-form/core owns the data layer: JSON-safe schemas, validation rules, serialization, renderer keys, custom validator references, and TanStack-compatible options. Framework packages render those definitions. It stays close to TanStack Form and Valibot instead of wrapping them in a second abstraction layer.

Quick Start

import {
  defineForm,
  deserializeForm,
  FieldDataType,
  type InferFormValues,
  serializeForm,
  toTanStackOptions,
  toValibotSchema,
  ValidationRuleKind,
} from '@tgb-form/core';

const form = defineForm({
  fields: {
    email: {
      type: FieldDataType.String,
      defaultValue: '',
      label: 'Email',
      component: 'email-input',
      props: { autocomplete: 'email' },
      rules: [
        { kind: ValidationRuleKind.Required, message: 'Email is required' },
        { kind: ValidationRuleKind.Email, message: 'Enter a valid email' },
      ],
    },
    subscribed: {
      type: FieldDataType.Boolean,
      defaultValue: true,
      label: 'Subscribe',
    },
  },
});

const stored = JSON.stringify(serializeForm(form));
const restored = deserializeForm(stored);
const schema = toValibotSchema(restored);
const tanstackOptions = toTanStackOptions(restored);

type FormValues = InferFormValues<typeof form>;
// { email: string; subscribed: boolean }

InferFormValues is the canonical way to derive the value shape of a code-authored definition. It follows each field's type, including number fields.

const checkoutDefinition = defineForm({
  fields: {
    quantity: { type: FieldDataType.Number, defaultValue: 1 },
  },
});

type FormValues = InferFormValues<typeof checkoutDefinition>;
// { quantity: number }

APIs

| API | Purpose | | ----------------------------------- | -------------------------------------------------------------------- | | defineForm(definition, options?) | Parse, validate, normalize, and clone a form definition. | | serializeForm(form) | Return JSON-safe data and omit runtime-only registries. | | deserializeForm(input, options?) | Parse a JSON string or unknown value into a normalized runtime form. | | toValibotSchema(form) | Compile the form into a Valibot object schema. | | toTanStackOptions(form, options?) | Generate default values and validators.onSubmit for TanStack Form. | | getDefaultValues(form) | Extract cloned default values from each field. | | createRendererRegistry(registry) | Create named and type-based renderer lookup tables. | | resolveRenderer(field, registry) | Resolve a field renderer by component, then by field type. | | createValidatorRegistry() | Register named custom validators used by JSON definitions. |

Typed JSON Restoration

JSON has no TypeScript type information, so deserializeForm(json) cannot infer a specific value shape from an unknown string or value. When the stored data is known to match a code-authored definition, supply that definition type explicitly:

const knownDefinition = defineForm({
  fields: {
    quantity: { type: FieldDataType.Number, defaultValue: 1 },
  },
});

const json = JSON.stringify(serializeForm(knownDefinition));
const restored = deserializeForm<typeof knownDefinition>(json);

type FormValues = InferFormValues<typeof restored>;
// { quantity: number }

Use this assertion only when the source of the JSON is trusted to follow the known definition. deserializeForm still validates every loaded value at runtime.

Renderer Keys

Core stores renderer keys, not framework components. Passing renderers to defineForm or deserializeForm is optional and mainly useful for component-name type narrowing and for carrying runtime registries alongside a normalized form object.

import { createRendererRegistry, FieldDataType, resolveRenderer } from '@tgb-form/core';

const renderers = createRendererRegistry({
  byName: {
    'email-input': EmailInput,
  },
  byType: {
    [FieldDataType.String]: TextInput,
    [FieldDataType.Boolean]: CheckboxInput,
  },
});

const Renderer = resolveRenderer(form.fields.email, renderers);

An explicit component must exist in byName. Fields without component fall back to byType[field.type].

Custom Validators

Custom validators keep code out of JSON. The definition stores a name; runtime code supplies the Valibot compiler.

import * as v from 'valibot';
import { createValidatorRegistry, defineForm, FieldDataType } from '@tgb-form/core';

const validators = createValidatorRegistry().register('companyEmail', ({ message }) =>
  v.check((value: string) => value.endsWith('@example.com'), message),
);

const form = defineForm(
  {
    fields: {
      email: {
        type: FieldDataType.String,
        defaultValue: '',
        validators: [{ name: 'companyEmail', message: 'Use a company email' }],
      },
    },
  },
  { validators },
);