Files
typemap/example/index.ts
glm-5.1 3b4dd4f1d1 Fork @sinclair/typemap to @alkdev/typemap with @alkdev/typebox backend
- 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
2026-04-23 15:36:51 +00:00

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;
// }>