@vielzeug/spell
v1.1.1
Published
Schema-first validation and parsing — runtime type checking, coercion, and custom refinements
Downloads
288
Readme
@vielzeug/spell
Zero-dependency schema validation library with strict-by-default objects, unified sync/async
validate(), coercion, flexible schema composition, and full TypeScript inference.
Package: @vielzeug/spell · Category: Validation
Key exports: s, SpellValidationError, setMessages, setLogger, resetMessages, ErrorCode, errorsAt, descriptorToJsonSchema
When to use: Zero-dependency schema validation library with strict-by-default objects, async refinements, coercion, flexible schema composition, and full TypeScript inference.
Related: @vielzeug/forge · @vielzeug/courier · @vielzeug/vault
@vielzeug/spell is part of Vielzeug and ships as a zero-dependency TypeScript package with ESM+CJS output.
Installation
pnpm add @vielzeug/spell
npm install @vielzeug/spell
yarn add @vielzeug/spellQuick Start
import { s, type Infer } from '@vielzeug/spell';
const UserSchema = s.object({
id: s.coerce.number().int().positive(),
name: s.string().trim().min(1),
email: s.string().trim().email(),
role: s.union('admin', 'editor', 'viewer').default('viewer'),
tags: s.array(s.string()).unique().default([]),
});
type User = Infer<typeof UserSchema>;
const result = UserSchema.safeParse({ id: '42', name: 'Ada', email: '[email protected]' });
if (result.success) {
const user: User = result.data;
console.log(user.id); // 42
// Assertion form — narrows type, throws SpellValidationError on failure
UserSchema.assert(result.data, 'user');
} else {
const { fieldErrors, formErrors } = result.error.flattenFirst();
console.log(fieldErrors, formErrors);
}Documentation
License
MIT © Helmuth Saatkamp — part of the Vielzeug monorepo.
