
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@sinclair/typebox-codegen
Advanced tools
npm install @sinclair/typebox-codegen
import * as Codegen from '@sinclair/typebox-codegen'
const Code = Codegen.TypeScriptToTypeBox.Generate(`
type T = { x: number, y: number, z: number }
`)
console.log(Code)
// Output:
//
// import { Type, Static } from '@sinclair/typebox'
//
// type T = Static<typeof T>
// const T = Type.Object({
// x: Type.Number(),
// y: Type.Number(),
// z: Type.Number()
// })
TypeBox-Codegen is a code generation tool that converts TypeScript types into TypeBox types as well as several other schema and library representations. It works by extracting structural type information from the TypeScript compiler and maps into a TypeBox specific model. This model can then be passed on to various code generators to generate a multitude of various type representations by introspecting TypeBox's schematics.
The library contains various code transformations for libraries such as zod, io-ts, arktype and valibot, assert function generators for JavaScript and TypeScript (derived from the TypeCompiler) as well as JSON Schema generation derived from TypeBox's raw schematics.
License MIT
The following is the general usage
import * as Codegen from '@sinclair/typebox-codegen'
const Code = `
export type T = {
x: number,
y: number,
z: number
}
`
// ----------------------------------------------------------------------------
//
// TypeScriptToTypeBox
//
// Generates an immediate TypeScript to TypeBox type code transformation
//
// ----------------------------------------------------------------------------
console.log('TypeScript To TypeBox', Codegen.TypeScriptToTypeBox.Generate(Code))
// ----------------------------------------------------------------------------
//
// TypeScriptToModel
//
// Generates an in-memory TypeBox Type Model
//
// ----------------------------------------------------------------------------
const model = Codegen.TypeScriptToModel.Generate(Code)
// ----------------------------------------------------------------------------
//
// ModelToX
//
// The TypeBox Type Model can be passed to several generators which map the
// Model into varying type representations.
//
// ----------------------------------------------------------------------------
console.log('TypeBoxModel', model)
console.log('Model To JsonSchema', Codegen.ModelToJsonSchema.Generate(model))
console.log('Model To JavaScript', Codegen.ModelToJavaScript.Generate(model))
console.log('Model To TypeScript', Codegen.ModelToTypeScript.Generate(model))
console.log('Model To Valibot', Codegen.ModelToValibot.Generate(model))
console.log('Model To Value', Codegen.ModelToValue.Generate(model))
console.log('Model To Yup', Codegen.ModelToYup.Generate(model))
console.log('Model To Zod', Codegen.ModelToZod.Generate(model))
console.log('Model To ArkType', Codegen.ModelToArkType.Generate(model))
Clone the project and run the following commands.
$ npm install # install dependencies
$ npm format # prettier pass for `src` and `example`
$ npm clean # remove the `target` directory.
$ npm start # run the `example` script in node
Set up pre-commit formatting hook by running cp ./.git-hooks/pre-commit ./.git/hooks/
FAQs
Code Generation Tools for TypeBox
The npm package @sinclair/typebox-codegen receives a total of 56,579 weekly downloads. As such, @sinclair/typebox-codegen popularity was classified as popular.
We found that @sinclair/typebox-codegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.