@vielzeug/forge
v1.2.1
Published
Type-safe form state — field-level validation, submission, dirty tracking, field arrays, and async default values
Readme
@vielzeug/forge
Framework-agnostic typed form state with path-safe fields, unified validation API, deterministic submit flow, and browser-friendly helpers.
Package: @vielzeug/forge · Category: Forms
Key exports: createForm, toFormData, ValidationModes, FORM_ERROR
When to use: Typed form state with field validation, dirty tracking, submission handling, and browser helpers. Works with any UI framework or vanilla JS.
Related: @vielzeug/spell · @vielzeug/ripple · @vielzeug/courier
@vielzeug/forge is part of Vielzeug and ships as a zero-dependency TypeScript package with ESM+CJS output.
Installation
pnpm add @vielzeug/forge
npm install @vielzeug/forge
yarn add @vielzeug/forgeQuick Start
import { createForm } from '@vielzeug/forge';
const form = createForm({
defaultValues: { email: '', password: '' },
validators: {
email: (v) => (!String(v).includes('@') ? 'Invalid email' : undefined),
password: (v) => (String(v).length < 8 ? 'Min 8 chars' : undefined),
},
});
form.set('email', '[email protected]');
const result = await form.validate();
console.log(result.valid, result.errors);
const submission = await form.submit(async (values) => {
await fetch('/api/login', {
body: JSON.stringify(values),
headers: { 'Content-Type': 'application/json' },
method: 'POST',
});
});
if (!submission.ok && submission.type === 'validation') {
console.log(submission.errors);
}Documentation
License
MIT © Helmuth Saatkamp — part of the Vielzeug monorepo.
