Gathering detailed insights and metrics for @sinclair/typebox-adapter
Gathering detailed insights and metrics for @sinclair/typebox-adapter
Syntax, Compiler and Translation System for Runtime Types
npm install @sinclair/typebox-adapter
Typescript
Module System
Node Version
NPM Version
TypeScript (98.92%)
JavaScript (1.08%)
Total Downloads
967
Last Day
104
Last Week
398
Last Month
826
Last Year
967
61 Stars
31 Commits
1 Forks
1 Watching
2 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
0.9.1
Package Id
@sinclair/typebox-adapter@0.9.1
Unpacked Size
162.54 kB
Size
17.90 kB
File Count
38
NPM Version
10.9.2
Node Version
23.6.0
Publised On
16 Jan 2025
Cumulative downloads
Total Downloads
Last day
57.6%
104
Compared to previous day
Last week
46.9%
398
Compared to previous week
Last month
485.8%
826
Compared to previous month
Last year
0%
967
Compared to previous year
1
1$ npm install @sinclair/typebox-adapter --save
TypeBox Adapter converts Valibot and Zod Types into TypeBox compatible schematics
1import { Box } from '@sinclair/typebox-adapter' 2 3import * as v from 'valibot' 4import * as z from 'zod' 5 6// Valibot to TypeBox (Runtime) 7 8const V = Box(v.object({ // const V = { 9 x: v.number(), // type: 'object', 10 y: v.number(), // required: ['x', 'y', 'z'], 11 z: v.number() // properties: { 12})) // x: { type: 'number' }, 13 // y: { type: 'number' }, 14 // z: { type: 'number' } 15 // } 16 // } 17 18// Zod to TypeBox (Static) 19 20const Z = Box(z.object({ // const Z: TObject<{ 21 a: z.string(), // a: TString, 22 b: z.string(), // b: TString, 23 c: z.string() // c: TString 24})) // }>
TypeBox Adapter converts Zod and Valibot types into TypeBox schematics (Json Schema). It performs a deep structural remapping of the types provided by these libraries into TypeScript-aligned Json Schema, enabling integration with industry-standard validators like Ajv and OpenAPI-related technologies, while also facilitating interoperability and acceleration via the TypeBox validation infrastructure.
License MIT
TypeBox Adapter provides a singular Box function to transform Valibot and Zod types into TypeBox schematics. The top-level export is capable of transforming both Valibot and Zod, but you should use the appropriate submodule depending on which library you are using.
Use the /valibot
submodule if you only have Valibot installed. Refer to the Valibot documentation for more information on this type library.
1import { Box } from '@sinclair/typebox-adapter/valibot' // Transform Valibot Only 2 3import * as v from 'valibot' 4 5const T = Box(v.string()) // const T = { type: 'string' }
Use the /zod
submodule if you only have Zod installed. Refer to the Zod documentation for more information on this type library.
1import { Box } from '@sinclair/typebox-adapter/zod' // Transform Zod Only 2 3import * as z from 'zod' 4 5const T = Box(z.string()) // const T = { type: 'string' }
This project manages a benchmark that evaluates type-check performance using Zod, Valibot, and TypeBox validators. The benchmark is set up to run 10 million check operations per library-validator pairing and reports the elapsed time taken to complete.
Benchmarks are run for the following type.
1type T = { x: number, y: string, z: boolean }
Results show validate performance for the type.
1┌─────────┬────────────────┬────────────────────┬────────────┬────────────┐ 2│ (index) │ library │ using │ iterations │ elapsed │ 3├─────────┼────────────────┼────────────────────┼────────────┼────────────┤ 4│ 0 │ 'valibot ' │ 'valibot ' │ 10000000 │ '1534 ms ' │ 5│ 1 │ 'valibot ' │ 'typebox:value ' │ 10000000 │ '1377 ms ' │ 6│ 2 │ 'valibot ' │ 'typebox:compile ' │ 10000000 │ '46 ms ' │ 7└─────────┴────────────────┴────────────────────┴────────────┴────────────┘ 8┌─────────┬────────────────┬────────────────────┬────────────┬────────────┐ 9│ (index) │ library │ using │ iterations │ elapsed │ 10├─────────┼────────────────┼────────────────────┼────────────┼────────────┤ 11│ 0 │ 'zod ' │ 'zod ' │ 10000000 │ '4669 ms ' │ 12│ 1 │ 'zod ' │ 'typebox:value ' │ 10000000 │ '1359 ms ' │ 13│ 2 │ 'zod ' │ 'typebox:compile ' │ 10000000 │ '47 ms ' │ 14└─────────┴────────────────┴────────────────────┴────────────┴────────────┘
For community benchmarks, refer to the runtime-type-benchmarks project.
This project is open to community contributions. Please ensure you submit an open issue before creating a pull request. TypeBox and its associated projects encourage open community discussion before accepting new features.
No vulnerabilities found.
No security vulnerabilities found.