@jdsalasc/solvejs-schema
v1.0.0
Published
Zero-dependency JavaScript/TypeScript schema validation with parse/safeParse, coercion, typed inference, and JSON Schema export.
Maintainers
Readme
@jdsalasc/solvejs-schema
Zero-dependency schema validation for JavaScript and TypeScript with typed inference and JSON Schema export.
Utilities
s.string(),s.number(),s.boolean(),s.date()s.literal(),s.array(),s.object(),s.union()parse,safeParseoptionals.refinetoJsonSchemaInfer
When to use this package
Use it when you need one schema definition for runtime validation, TypeScript types, and JSON Schema generation.
Limitations and Constraints
- Object parser only returns declared shape keys.
- Optional fields are represented via
optional()in schema shape. - JSON Schema export is pragmatic and intentionally scoped.
Install
npm i @jdsalasc/solvejs-schemaQuick example
import { s, type Infer, toJsonSchema } from "@jdsalasc/solvejs-schema";
const userSchema = s.object({
id: s.string().uuid(),
age: s.number({ coerce: true }).int().min(18),
email: s.string({ trim: true }).email(),
newsletter: s.boolean({ coerce: true }).optional()
});
type User = Infer<typeof userSchema>;
const parsed = userSchema.safeParse({
id: "550e8400-e29b-41d4-a716-446655440000",
age: "21",
email: "[email protected]",
newsletter: "true"
});
const jsonSchema = toJsonSchema(userSchema);