{"id":14156083,"url":"https://github.com/sinclairzx81/typebox-codegen","last_synced_at":"2025-04-05T01:07:35.265Z","repository":{"id":185107819,"uuid":"626349478","full_name":"sinclairzx81/typebox-codegen","owner":"sinclairzx81","description":"Code Generation for TypeBox Types","archived":false,"fork":false,"pushed_at":"2024-09-09T11:31:19.000Z","size":3108,"stargazers_count":135,"open_issues_count":7,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-29T18:08:29.516Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinclairzx81.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-11T09:38:47.000Z","updated_at":"2024-10-23T12:56:19.000Z","dependencies_parsed_at":"2024-03-28T04:26:52.097Z","dependency_job_id":"1d2d8efc-80aa-491b-8f1d-5a3360cd4aa8","html_url":"https://github.com/sinclairzx81/typebox-codegen","commit_stats":{"total_commits":77,"total_committers":6,"mean_commits":"12.833333333333334","dds":"0.19480519480519476","last_synced_commit":"7a859390ab29032156d8da260038b45cf63fc5a4"},"previous_names":["sinclairzx81/typebox-codegen"],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypebox-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypebox-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypebox-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypebox-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairzx81","download_url":"https://codeload.github.com/sinclairzx81/typebox-codegen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271530,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-17T08:05:12.356Z","updated_at":"2025-04-05T01:07:35.247Z","avatar_url":"https://github.com/sinclairzx81.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","others"],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n\n\u003ch1\u003eTypeBox-Codegen\u003c/h1\u003e\n\n\u003cp\u003eCode Generation Tools for TypeBox\u003c/p\u003e\n\n\u003cimg src=\"https://github.com/sinclairzx81/typebox-codegen/blob/main/codegen.png?raw=true\" /\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n[![npm version](https://badge.fury.io/js/%40sinclair%2Ftypebox-codegen.svg)](https://badge.fury.io/js/%40sinclair%2Ftypebox-codegen)\n[![GitHub CI](https://github.com/sinclairzx81/typebox-codegen/actions/workflows/ci.yml/badge.svg)](https://github.com/sinclairzx81/typebox-codegen/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u003c/div\u003e\n\n## Install\n\n```typescript\nnpm install @sinclair/typebox-codegen\n```\n\n## Example\n\n```typescript\nimport * as Codegen from '@sinclair/typebox-codegen'\n\nconst Code = Codegen.TypeScriptToTypeBox.Generate(`\n  type T = { x: number, y: number, z: number }\n`)\n\nconsole.log(Code)\n\n// Output:\n//\n// import { Type, Static } from '@sinclair/typebox'\n// \n// type T = Static\u003ctypeof T\u003e\n// const T = Type.Object({\n//   x: Type.Number(),\n//   y: Type.Number(),\n//   z: Type.Number()\n// })\n```\n\n## Overview\n\nTypeBox-Codegen is a code generation tool that transforms TypeScript types into TypeBox types as well as several other schema and library representations. It works by mapping structural type information from the TypeScript compiler into a TypeBox model. This model is then passed on to code generators which generate via TypeBox schema introspection.\n\nThe library contains code transformations for libraries such as [zod](https://github.com/colinhacks/zod), [effect](https://github.com/Effect-TS/effect), [arktype](https://github.com/arktypeio/arktype), [io-ts](https://github.com/gcanti/io-ts) and [valibot](https://github.com/fabian-hiller/valibot), assertion generators for JavaScript and TypeScript as well as Json Schema derived from TypeBox's raw schematics.\n\n[TypeBox Workbench Example](https://sinclairzx81.github.io/typebox-workbench/)\n\nLicense MIT\n\n## Usage\n\nThe following is the general usage\n\n```typescript\nimport * as Codegen from '@sinclair/typebox-codegen'\n\nconst Code = `\nexport type T = {\n  x: number,\n  y: number,\n  z: number\n}\n`\n// ----------------------------------------------------------------------------\n//\n// TypeScriptToTypeBox\n//\n// Generates an immediate TypeScript to TypeBox type code transformation\n//\n// ----------------------------------------------------------------------------\n\nconsole.log('TypeScript To TypeBox', Codegen.TypeScriptToTypeBox.Generate(Code))\n\n// ----------------------------------------------------------------------------\n//\n// TypeScriptToModel\n//\n// Generates an in-memory TypeBox Model\n//\n// ----------------------------------------------------------------------------\n\nconst model = Codegen.TypeScriptToModel.Generate(Code)\n\n// ----------------------------------------------------------------------------\n//\n// ModelToX\n//\n// The TypeBox Model can be passed to several generators which map the\n// Model into varying type representations.\n//\n// ----------------------------------------------------------------------------\n\nconsole.log('TypeBoxModel', model)\nconsole.log('Model To JsonSchema', Codegen.ModelToJsonSchema.Generate(model))\nconsole.log('Model To JavaScript', Codegen.ModelToJavaScript.Generate(model))\nconsole.log('Model To TypeScript', Codegen.ModelToTypeScript.Generate(model))\nconsole.log('Model To Valibot', Codegen.ModelToValibot.Generate(model))\nconsole.log('Model To Value', Codegen.ModelToValue.Generate(model))\nconsole.log('Model To Yup', Codegen.ModelToYup.Generate(model))\nconsole.log('Model To Zod', Codegen.ModelToZod.Generate(model))\nconsole.log('Model To ArkType', Codegen.ModelToArkType.Generate(model))\nconsole.log('Model To Effect', Codegen.ModelToEffect.Generate(model))\n```\n\n## Running Local\n\nClone the project and run the following commands.\n\n```bash\n$ npm install      # install dependencies\n\n$ npm format       # prettier pass for `src` and `example`\n\n$ npm clean        # remove the `target` directory.\n\n$ npm start        # run the `example` script in node\n```\n\n## Formatting hook\n\nSet up pre-commit formatting hook by running `cp ./.git-hooks/pre-commit ./.git/hooks/`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Ftypebox-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairzx81%2Ftypebox-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Ftypebox-codegen/lists"}