- Rename package to @alkdev/typemap, update peerDeps to @alkdev/typebox - Replace all @sinclair/typebox imports with @alkdev/typebox - Replace @sinclair/hammer build system with standalone build.mjs - Remove upstream-only files (.github, .vscode, design/, typemap.png) - Update readme with fork notice and new package names - Add fork copyright to license
47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import { TypeBox, Valibot, Zod, Syntax, Compile } from '@alkdev/typemap'
|
|
|
|
// ------------------------------------------------------------------
|
|
// Syntax Types
|
|
// ------------------------------------------------------------------
|
|
|
|
const S = `{
|
|
x: number,
|
|
y: number,
|
|
z: number
|
|
}`
|
|
|
|
// ------------------------------------------------------------------
|
|
// Runtime Types
|
|
// ------------------------------------------------------------------
|
|
|
|
const T = TypeBox(S) // const T: TObject<{ ... }>
|
|
|
|
const V = Valibot(S) // const V: ObjectSchema<{ ... }, ...>
|
|
|
|
const Z = Zod(S) // const Z: ZodObject<{ ... }, ...>
|
|
|
|
// ------------------------------------------------------------------
|
|
// Reverse Syntax
|
|
// ------------------------------------------------------------------
|
|
|
|
const X = Syntax(Z) // const X: "{ x: number, y: number, z: number }"
|
|
|
|
// ------------------------------------------------------------------
|
|
// Compile
|
|
// ------------------------------------------------------------------
|
|
|
|
const C = Compile(X) // const C: Validator<TObject<{
|
|
// x: TNumber;
|
|
// y: TNumber;
|
|
// z: TNumber;
|
|
// }>>
|
|
|
|
// ------------------------------------------------------------------
|
|
// Validate | Standard
|
|
// ------------------------------------------------------------------
|
|
|
|
const R = C['~standard'].validate(null) // const R: StandardSchemaV1.Result<{
|
|
// x: number;
|
|
// y: number;
|
|
// z: number;
|
|
// }>
|