{"id":25249418,"url":"https://github.com/sinclairzx81/typemap","last_synced_at":"2025-05-16T14:07:13.321Z","repository":{"id":269581628,"uuid":"907843729","full_name":"sinclairzx81/typemap","owner":"sinclairzx81","description":"Syntax Compiler and Translation System for Runtime Types","archived":false,"fork":false,"pushed_at":"2025-04-02T14:07:54.000Z","size":10603,"stargazers_count":148,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-13T14:22:00.251Z","etag":null,"topics":["compile","json-schema","parse","syntax","typebox","typescript","valibot","zod"],"latest_commit_sha":null,"homepage":"","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,"zenodo":null}},"created_at":"2024-12-24T14:27:50.000Z","updated_at":"2025-05-13T05:00:13.000Z","dependencies_parsed_at":"2025-04-12T14:19:20.948Z","dependency_job_id":"f1f614ca-d061-4e7e-bf5d-3015ca53663e","html_url":"https://github.com/sinclairzx81/typemap","commit_stats":null,"previous_names":["sinclairzx81/typebox-remix","sinclairzx81/typebox-adapter","sinclairzx81/typemap"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Ftypemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairzx81","download_url":"https://codeload.github.com/sinclairzx81/typemap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"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":["compile","json-schema","parse","syntax","typebox","typescript","valibot","zod"],"created_at":"2025-02-12T03:21:44.992Z","updated_at":"2025-05-16T14:07:13.304Z","avatar_url":"https://github.com/sinclairzx81.png","language":"TypeScript","readme":"\u003cdiv align='center'\u003e\n\n\u003ch1\u003eTypeMap\u003c/h1\u003e\n\n\u003cp\u003eSyntax Compiler and Translation System for Runtime Types\u003c/p\u003e\n\n\u003cimg src=\"./typemap.png\" /\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n[![npm version](https://badge.fury.io/js/%40sinclair%2Ftypemap.svg)](https://badge.fury.io/js/%40sinclair%2Ftypemap)\n![Downloads](https://img.shields.io/npm/dm/%40sinclair%2Ftypemap)\n[![Build](https://github.com/sinclairzx81/typemap/actions/workflows/build.yml/badge.svg)](https://github.com/sinclairzx81/typemap/actions/workflows/build.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```bash\n$ npm install @sinclair/typemap --save\n```\n\n## Usage\n\nParse and Compile Types from TypeScript Syntax ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199\u0026ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgYQuYAbApnAvnAMyjTgHIABAZ2ADsBjDAQ2CgHoYBPMLERsUgFADWrFGjCYcAFS5ZKcAOrAYACzgBlDjRiMAHkLoQaleADdGGYABNGMaHAC8Y9NgAUAAySMAXHBNRaAHMAGjgAI19-ILx3AEo4EThDYzMLa1toXwA1NJs7KAAeKQB5MIArLDoYAoQBOHqGxqbmlta2tsT6nzgpdRgAmhC69pHRsZbO8N9e-qDh8YXFidFcAD5VoUScyzycAHdlNT7GGhsoKw06FR5GAyMTOCg5AFcMeCdzHYyoAG1SAD8TCczlZSABdAB0n3SMCwriQTUSyQeT0orxgvmOp0Y53UVxuWQAjBCAEovN41YbdUjXDAYCCkUJLZmI0RdSKzQbBYYRMh7aAYUEs4UNSa8qKDAS4eIi2WtRJrIA))\n\n```typescript\nimport { Compile } from '@sinclair/typemap'\n\n// Compile Types With Syntax\n\nconst validator = Compile(`{ a: string, b: string }`) // const validator: Validator\u003cTObject\u003c{\n                                                      //   a: TString,\n                                                      //   b: TString\n                                                      // }\u003e\u003e\n\n// Validate with Standard Schema\n\nconst result = validator['~standard'].validate({      // const result: StandardSchemaV1.Result\u003c{\n  a: 'hello',                                         //   a: string,\n  b: 'world'                                          //   b: string\n})                                                    // }\u003e\n```\n\n## Overview\n\nTypeMap is a syntax frontend and compiler backend for the [TypeBox](https://github.com/sinclairzx81/typebox), [Valibot](https://github.com/fabian-hiller/valibot) and [Zod](https://github.com/colinhacks/zod) runtime type libraries. It offers a common TypeScript syntax for type construction, a runtime compiler for high-performance validation and type translation from one library to another.\n\nTypeMap is written as an advanced type mapping system for the TypeBox project. It is designed to accelerate remote type libraries on TypeBox infrastructure as well enabling TypeBox to integrate with remote type library infrastructure via reverse type remapping. This project also offers high-performance validation for frameworks that orientate around the [Standard Schema](https://github.com/standard-schema/standard-schema) TypeScript interface.\n\nLicense: MIT\n\n## Contents\n\n- [Install](#Install)\n- [Usage](#Usage)\n- [Overview](#Overview)\n- [Example](#Example)\n- [Mapping](#Section-Mapping)\n  - [Syntax](#Mapping-Syntax)\n  - [TypeBox](#Mapping-TypeBox)\n  - [Valibot](#Mapping-Valibot)\n  - [Zod](#Mapping-Zod)\n- [Syntax](#Section-Syntax)\n  - [Types](#Syntax-Types)\n  - [Options](#Syntax-Options)\n  - [Parameters](#Syntax-Parameters)\n  - [Generics](#Syntax-Generics)\n- [Static](#Section-Static)\n- [Json Schema](#Json-Schema)\n- [Tree Shake](#Tree-Shake)\n- [Compile](#Compile)\n- [Benchmark](#Benchmark)\n- [Contribute](#Contribute)\n\n## Example\n\nUse TypeScript syntax to create types for TypeBox, Valibot and Zod ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA8A0cAagIYA2wARhDIQFoQAmcAvnAGZQQhwDkAAgGdgAOwDGZEsCgB6GOgwgSYXgChVMmXADKqETBK4UCwerEQRg+NrgBeOAAMEquHFwAuOCICuIShih8FzhUTx8-AKDXAC8w338oVRYHdU04ACVvfVAMY0xTVXNLeGQ7POw8AAptAEpXeobGpubGtKKrFE9kAHlKACsMMRgAHiQAOgnWAD4zCw6iMtIKahhqupaNzYa2ufgiT16Boe0xAAtFElG4CbHWQhuZwt24OjKGRjWtr++d4pfPd6HQYjcaTFj3CZTIA))\n\n```typescript\nimport { TypeBox, Valibot, Zod } from '@sinclair/typemap'\n\n// Syntax Types\n\nconst S = `{\n  x: number,\n  y: number,\n  z: number\n}`\n\n// Runtime Types\n\nconst T = TypeBox(S)                                // const T: TObject\u003c{ ... }\u003e\n\nconst V = Valibot(S)                                // const V: ObjectSchema\u003c{ ... }, ...\u003e\n\nconst Z = Zod(S)                                    // const Z: ZodObject\u003c{ ... }, ...\u003e\n```\n\nTranslate TypeBox, Valibot and Zod types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA8A0cAagIYA2wARhDIQFoQAmcAvnAGZQQhwDkAAgGdgAOwDGZEsCgB6GOgwgSYXgChVMmXADKqETBK44AWgB8cBszPFyVGifNpMOXOrEQRg+MjgBeFAouABSkFNQwQZZBAAYIqnBwuABccCIAriCUGFD48XCoKemZ2bkJAF6FGVlQqizRAJSNQA))\n\n```typescript\nimport { TypeBox, Valibot, Zod } from '@sinclair/typemap'\n\n// Syntax -\u003e Zod -\u003e Valibot -\u003e TypeBox\n\nconst T = TypeBox(Valibot(Zod(`{\n  x: number,\n  y: number,\n  z: number\n}`)))\n```\n\nCompile Valibot and Zod types on TypeBox infrastructure ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgYQuYAbApnAvnAMyjTgHIABAZ2ADsBjDAQ2CgHoYBPMLERsUgFADQkWHABehYiDLiIAE0EDWrOAC0FcACpcsQuhBqV4auAF4JAOggAjAFZY6MABRI47j56-efHlXAMjEwAudQUAeXtHGAAeNwF3AA9Q8UsaAFcQGywoZwBKABpfYpLi-yTQjXkAOUzsqCLPBLgOFLS6nPzG0p7S8pbKhVqsnILm8TaMkdzC3rmy1XcJsJqOqAFcPPntnfd-XAA+IX8AJR4+OEYaeRQ0MEw9AUDjFHNb9GxnNS3d3v9n+DIUIANUYGGA8kYMGgMS0kQcTji7mav1RfUWcGS2mG9W6yLRBIWHla2LWY0JFK8-WWWhxORRlIp+wOR2UqgAEsAAOYAC20POI6V5EHS8FB4MhMGAhn0hheJzeyEsyB5jgA1q5GT5-ABJGA5KHSoyhACMAAYAPpm61W63NLEmvFauYqZokgBMTudPX8VV8oQALNazSBKHBnHwwMREnlxqEAMzenb+HTcACyFw8gZDYfcEbAUYgMY2eSAA))\n\n```typescript\nimport { Compile } from '@sinclair/typemap'\n\nimport z from 'zod'\n\n// Zod Type\n\nconst Z = z.object({                                // const Z: ZodObject\u003c{  \n  x: z.number(),                                    //   x: ZodNumber,     \n  y: z.number(),                                    //   y: ZodNumber,\n  z: z.number(),                                    //   z: ZodNumber\n})                                                  // }\u003e\n\n// Remap and Compile\n\nconst C = Compile(Z)                                // const C: Validator\u003cTObject\u003c{  \n                                                    //   x: TNumber,     \n                                                    //   y: TNumber,\n                                                    //   z: TNumber\n                                                    // }\u003e\u003e\n\n// High Throughout Validation\n\nconst R = C.Check({                                 // Iterations: 10_000_000\n  x: 1,                                             //\n  y: 2,                                             // Zod        : 4000ms (approx)\n  z: 3                                              // TypeMap    : 40ms   (approx)\n})\n```\n\n\u003ca name=\"Section-Mapping\"\u003e\u003c/a\u003e\n\n## Mapping\n\nTypeMap is designed for runtime type translation. It provides one mapping function per library which can be used to translate remote types into types specific to that library. All mapping functions make a best effort attempt to translate the structures and semantics from each library. If no translation is possible, these functions return a `never` representation.\n\n\u003ca name=\"Mapping-Syntax\"\u003e\u003c/a\u003e\n\n### Syntax\n\nUse the `Syntax` function to translate types into a Syntax string ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYhZgKAKCGhIsOACo4WGnHgkylWvWasOXXgCMIOYWOjxpsuADdipchVNYmwHTH3hDUmXIBeFpRXcQAJsJCDBDoNPDIcAC8KBjYOAAUFGFQ9ADmANoAuhQAlHD5BYVFxQXs7HDBoeEAXJTJaVkUxfFomLg5QSFhcAAqUTFtCTAAdAByAK4gWjxQ8Tl5JYuLZRVd8D21FOiT01BNJfE93DwAQrodld0Aav2tcfGmw-XoqXMLSx+l5ZfwV5vPqX2zSutnsEBgFzWcAAWrdYrh4u5hjoIEweFh0G9PtiVj8YZsUWiMUDCvFof4ckA))\n\n```typescript\nimport { Syntax } from '@sinclair/typemap'\n\nconst S = Syntax('string[]')                        // const S: 'string[]'      (Syntax)\nconst T = Syntax(t.Number())                        // const T: 'number'        (TypeBox)\nconst V = Syntax(v.string())                        // const V: 'string'        (Valibot)\nconst Z = Syntax(z.boolean())                       // const Z: 'boolean'       (Zod)\n```\n\n\u003ca name=\"Mapping-TypeBox\"\u003e\u003c/a\u003e\n\n### TypeBox\n\nUse the `TypeBox` function to translate types and syntax into TypeBox types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA84C+cAZlBCHAOQACAzsAHYDGANgIbBQD0M6GIbMJQBQw0JFhwAVHDa048UuSp1GrDt16YARnhHjo8GXLgA3EmQqVTbFsF0x94Q9NnyAXheWV3EACYiwkwQDLTwAMpwALwofDi4ABSUYVCMAOYA2gC6lACUcAWFRcUlBVxccMGhEQBcKACCUFBsqAA8yOEwqQxpAHxwCeGoDDBsuLlBIWEo0bGY8QkwAHQAcgCuINoYUAm5+aUHpeWVU-DIdcjrm9uHCWjzeBNV0wBqs-fYeAmmSynpu-tDkCyhVnvAXhdOt00rcXrZ7BAYE9TnAAFrvOJfdxLXQQFgYNgMAHA4HHMFoi44PEEhgHBKo-y5IA))\n\n```typescript\nimport { TypeBox } from '@sinclair/typemap'\n\nconst S = TypeBox('string[]')                       // const S: TArray\u003cTString\u003e (Syntax)\nconst T = TypeBox(t.Number())                       // const T: TNumber         (TypeBox)\nconst V = TypeBox(v.string())                       // const V: TString         (Valibot)\nconst Z = TypeBox(z.boolean())                      // const Z: TBoolean        (Zod)\n```\n\n\u003ca name=\"Mapping-Valibot\"\u003e\u003c/a\u003e\n\n### Valibot\n\nUse the `Valibot` function to translate types and syntax into Valibot types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgNQIYBtgCMLwL5wBmUEIcA5AAIDOwAdgMbqrBQD0MAnmAKYiphyAKCGhIsOACo4qanHjFSFGvSYt2XXjgAewsdHjTZcAG5ESZciYzZce8Aaky5AL3NLyLiABNhQhhB01PAAynAAvCg2ODAAFOTBUPQA5gDaALrkAJRwuXn5BYW5bGxwAUGhAFymAHQAglBQqJwhDAAWfKgAPDW9AHxwsSGcdDCo2ln+gcFwACoRUZgxsTA1AHIAriBYPFCxWTlFR0UlZdPws9Um61s7UK0d-AWxs9w8AEIQE1MVKAtoS1wsWuiRS+0Ox0hxVK5RmyCuNRCMCSdGSD06zwBthgk1h8AAWv9okCXDUcBB0DxUHRwVCoac8XB8QjPhSqXR0U88rF8T4skA))\n\n```typescript\nimport { Valibot } from '@sinclair/typemap'\n\nconst S = Valibot('string[]')                       // const S: v.ArraySchema\u003c...\u003e (Syntax)\nconst T = Valibot(t.Number())                       // const T: v.NumberSchema     (TypeBox)\nconst V = Valibot(v.string())                       // const V: v.StringSchema     (Valibot)\nconst Z = Valibot(z.boolean())                      // const Z: v.BooleanSchema    (Zod)\n```\n\n\u003ca name=\"Mapping-Zod\"\u003e\u003c/a\u003e\n\n### Zod\n\nUse the `Zod` function to translate types and syntax into Zod types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgLQgEzgXzgMyhEOAcgAEBnYAOwGMAbAQ2CgHoYBPMAUxHrCICh+oSLDgAqOPTJx4eAsXJU6jFuy4AjCAA8Bw6PAlS4AN1z5CRY-VrBNMXeH3jJ0gF5n5RV+gH9qESjJ4AGU4AF4UdAAKIiCoKgBzAG0AXSIASjgs7JzcvLzmZjh-QJCALjhXADpUNABBKCh6NgAeKvaAPjgo4LZKGHotdL8AoLgAFXDItCiYKoA5AFcQdU4oKPTM-O2drMLi0fhxiurapZW13Kjxjk4AIW1hkrGANSnaqOMquMSNrd2ATl9s94C8TjV0MEYPFKAkri9rLYIDAnocUO9otVNBBaJx6JQ-oCiXBgWjkODag8cXjKDkorV0kA))\n\n```typescript\nimport { Zod } from '@sinclair/typemap'\n\nconst S = Zod('string[]')                           // const S: z.ZodArray\u003c...\u003e (Syntax)\nconst T = Zod(t.Number())                           // const T: z.ZodNumber     (TypeBox)\nconst V = Zod(v.string())                           // const V: z.ZodString     (Valibot)\nconst Z = Zod(z.boolean())                          // const Z: z.ZodBoolean    (Zod)\n```\n\n\u003ca name=\"Section-Syntax\"\u003e\u003c/a\u003e\n\n## Syntax\n\nTypeMap provides an optional TypeScript syntax parser that can be used to construct library types. Syntax parsing is implemented at runtime as well as in the type system. This feature can be used to uniformly construct types across libraries, as well as create types with embedded remote types.\n\n\u003ca name=\"Syntax-Types\"\u003e\u003c/a\u003e\n\n### Types\n\nSyntax types can be created by passing a string parameter to any library mapping function. TypeMap supports most TypeScript syntax. If the string contains a syntax error, the function will return a `never` type. ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA84C+cAZlBCHAOQACAzsAHYDGANgIbBQD0M6GIbMJQBQwphAa14yOAF4UfHLgAUlJLgBccAIwAaOKi0AmQpQCUcS1es3LXLnHGTpW5AHkARgCsMTGAB4kYVsQ0LDwiLh7K00UABlgGAwoNhZ-bQA+XWDI3LzI6MtDeMTk1P8jDJz8mtq7BwIqsQkpOABlOQVMJVUAQn7zOvDop1a21wA5DAA3ZLgAWnbUBhg2fABRKDIoIA))\n\n```typescript\nimport { TypeBox } from '@sinclair/typemap'\n\nconst T = TypeBox('{ x: 1, y: 2 }')                 // const T: TObject\u003c{ \n                                                    //   x: TLiteral\u003c1\u003e,\n                                                    //   y: TLiteral\u003c2\u003e\n                                                    // }\u003e\n\nconst S = TypeBox('!!!')                            // const S: TNever - Syntax Error\n```\n\n\u003ca name=\"Syntax-Options\"\u003e\u003c/a\u003e\n\n### Options\n\nYou can pass Json Schema options on the last parameter of a syntax type. TypeMap translates known [keywords](https://json-schema.org/understanding-json-schema/reference/type) into appropriate runtime representations if possible ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA8A0cAWhACZwC+cAZlBCHAOQACAzsAHYDGANgIbAoAehjoMIPmEYAoaVwgdW8ZHAC8KMTlwAKRkqicA5o0JI45i5avW4QoXHmLlALhQBlGAY6G1iaeepoCRhXRnEBHkYbaJjY23tzUUxQ-SMTaQoASjic3Ly7C0CoYNDw4Ej-PKrq6wKKWTkFJTg3XxJSXSRcAH5XDgBXEAAjDChKE0Qa8wLHZtb1AC8AOgghgCsMLhhtJEq+UlJgGGAFPh4ABTpMWGAMVldqM9YMKasC81xXZYHh0e1MlZgY6nHj-DLZV6Q2J1AGpLb-IA))\n\n```typescript\nimport { TypeBox, Zod } from '@sinclair/typemap'\n\nconst T = TypeBox('string', {                       // const T: TString = {\n  format: 'email'                                   //   type: 'string',\n})                                                  //   format: 'email'\n                                                    // }\n\n\nconst S = Zod('{ x?: number }', {                   // const S = z.object({ \n  additionalProperties: false                       //   x: z.number().optional()\n})                                                  // }).strict()\n```\n\n\u003ca name=\"Syntax-Parameters\"\u003e\u003c/a\u003e\n\n### Parameters\n\nSyntax types can be parameterized to receive exterior types. Parameters are automatically translated to the receiving type ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgNQIYBtgCMIwDRwBaEAJnAL5wBmUEIcA5AAIDOwAdgMbqrBQD0MAJ5gApiFRgGAKGmcI7FvGRwAvCgzZcACgbsAriCyioDAJRxLV6zdvX+-OPMXKAXHAByh41ADKnAAtxVFkHOAAFVChUEFEYExQ4CTAxMipoOBgogHM4ollnJSI1IlJtJBVyAgADJAA3DH1RFndkAG0AXQpqizsbMML4QndiEgB5LAArUU4YAB4kaT7lldW1yzDLBvQmltKSAEEoaKE50a8jEwA+JfW7++WwqsQ4ADp3iiugA))\n\n```typescript\nimport { Valibot, Zod } from '@sinclair/typemap'\n\nconst V = Valibot('number')                         // const V: NumberSchema\n\n// Parameter V mapped for target Z\n\nconst Z = Zod({ V }, `{ values: V[] }`)             // const Z: ZodObject\u003c{ \n                                                    //   values: ZodArray\u003cZodNumber\u003e\n                                                    // }, { ... }\u003e\n```\n\n\u003ca name=\"Syntax-Generics\"\u003e\u003c/a\u003e\n\n### Generics\n\nUse parameterized types with functions to create generic syntax types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA8A0cAagIYA2wARhDIQFoQAmcAvnAGZQQhwDkAAgGdgAOwDGZEsCgB6GOgwgSYXgChVMmXADiGERijAxKBerEQRg+EQxiY0OAF44AHmRwMuGHsaC4ESgArWxgAPgAKZAAuFABKJ1CTTBxccKR3FkIAAyRVODhcGORCPLhUIpL8gC8iuFUWLNj1TTgASUsYEnEMZjRMQTMLKxQnYhDocNIKahhw3hEAVxBKA15Y+PzNre38lvMOlCKAeSCQlwRSnavrm9vblvzClAA5JZWoSruv75+4B7Kiq9lgZ8JdfuCIX8tNVAW8QWDIYi7i0WKFBgcAMqjGx2CYMRhzKyGEQAczWG0ReyG8Axx1OdnOCKRzJ2-yeyAxMGJJM+LL523+5RQnO5oP54s2-xqwq5oh5TIlSJRoSAA))\n\n```typescript\nimport { TypeBox, Valibot, Zod } from '@sinclair/typemap'\n\n// Generic Type\n\nconst Vector = \u003cT extends object\u003e(T: T) =\u003e TypeBox({ T }, `{ \n  x: T, \n  y: T, \n  z: T \n}`)\n\n// Instanced Types\n\nconst T = Vector(Valibot('number'))                 // const T: TObject\u003c{\n                                                    //   x: TNumber, \n                                                    //   y: TNumber,\n                                                    //   z: TNumber,\n                                                    // }\u003e\n\nconst S = Vector(Zod('string'))                     // const S: TObject\u003c{\n                                                    //   x: TString, \n                                                    //   y: TString,\n                                                    //   z: TString,\n                                                    // }\u003e\n```\n\n## Static\n\nUse Static to infer for library and syntax types \n\n```typescript\nimport { type Static } from '@sinclair/typemap'\n\nconst T = t.Number()                                // TypeBox\nconst V = v.string()                                // Valibot\nconst Z = z.boolean()                               // Zod\nconst S = 'string[]'                                // Syntax\n\ntype S = Static\u003ctypeof S\u003e                           // string[]\ntype T = Static\u003ctypeof T\u003e                           // number\ntype V = Static\u003ctypeof V\u003e                           // string\ntype Z = Static\u003ctypeof Z\u003e                           // boolean \n```\n\n\u003ca name=\"Json-Schema\"\u003e\u003c/a\u003e\n\n## Json Schema\n\nUse `TypeBox` to transform remote library types into Json Schema ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgFQJ5gKYCEIA84CGAznAFJEQB2AygMYAWGIBcAvnAGZQQhwDkAASLBKtADYFgUAPQx0TAmD4AoZaEiw4AKkIkAXp268+eiABMVy2lSLwAWnAC8cPQDoIAIwBWGWjAAUSHDBIaFh4REh0tJw1pS2cHYAXC6uduYA8t6+MAA8CMrBuClulACuIB4YUP4AlAA0kU3NTdEhxanpZgByFVVQANyFcKglruWV1XWNLbOzbcGjnea9k4PDemMT-XVze80LLmNdq-1DrLWutlDAfrv7D60xrI0ARNe3MK+Nrr8AfKo2mhMDh8BhROYMCQ5JgSMQyBRKHA6IxmKo4glkE4EVQUQp-HZao95jEMfAsc4CsTqftDjCMCk+J4fH4+PVhjTOU8QlAMABHMpSDBmFIAbT4uDZ-FQUpMfAAuuyucqIocCGYzMAYMAqAQxAAFbiYWDAKEpDh6ogYJUq23BQ5gI3VbVmxAcu3Kw5FFJIemM7bVPhsG0ez0xUJLX3yf19QPB92hmleo6IOB+-gBqBB1gJxPEw45vNctqsIA))\n\n```typescript\nimport { TypeBox as JsonSchema } from '@sinclair/typemap'\n\nconst Z = z.object({                                // const Z: z.ZodObject\u003c{\n  x: z.number(),                                    //   x: z.ZodNumber;\n  y: z.number(),                                    //   y: z.ZodNumber;\n  z: z.number()                                     //   z: z.ZodNumber;\n}).strict()                                         // }, \"strict\", ...\u003e\n\n// TypeBox encodes types as Json Schema\n\nconst T = JsonSchema(Z)                             // const T = {\n                                                    //   type: 'object',\n                                                    //   required: ['x', 'y', 'z'],\n                                                    //   additionalProperties: false,\n                                                    //   properties: {\n                                                    //     x: { type: 'number' },\n                                                    //     y: { type: 'number' },\n                                                    //     z: { type: 'number' }\n                                                    //   }\n                                                    // }\n```\n\n\u003ca name=\"Tree-Shake\"\u003e\u003c/a\u003e\n\n## Tree Shake\n\nTypeMap takes on TypeBox, Valibot and Zod as peer dependencies. If bundling, it is recommended that you import specific translation functions. By doing this it will by-pass library imports and enable unused libraries to be omitted from the bundle.\n\n```typescript\nimport { TypeBoxFromZod } from '@sinclair/typemap'  // Use TypeBox \u0026 Zod, Tree Shake Valibot\n\nimport * as z from 'zod'\n\nconst T = TypeBoxFromZod(z.object({                 // const T: TObject\u003c{\n  x: z.number(),                                    //  x: TNumber;\n  y: z.number(),                                    //  y: TNumber;\n  z: z.number()                                     //  z: TNumber;\n}))                                                 // }\u003e\n```\n\n## Compile\n\nUse the `Compile` function to compile TypeBox, Valibot and Zod on TypeBox infrastructure ([Example](https://www.typescriptlang.org/play/?moduleResolution=99\u0026module=199#code/JYWwDg9gTgLgBAbzgYQuYAbApgGjgLQgBM4BfOAMyjTgHIABAZ2ADsBjDAQ2CgHoYAnmCwhOYWgCgJvXijRhMWAsTgAVIVilsILRvABunDMCKcY0OAF456bAApCROwAMEEuB4AeALjgsAriAARlhQOO4eAr4BwaHhHnAAXtGBIVASpM4AlFlaOnpwAEoAjFZwhsam5lAAdMgAFlhsANZ2SD5wxXhRcABMeMlwAMxkWQlwMnAAgmxsWNhQZlhEUpMAyjCcLKZQJGtsjaLSvMdwNedwAO71wAdwjPUQ-hgk9Zz6SiFYLH6cIMt0DZbHYkABqRhMZmgkgk2l08EKvTKFUh1QA2rQAH56YGcXa0AC6NRRVSwbTgHS6cB6-SSvhGpCyQA))\n\n```typescript\nimport { Compile, Zod } from '@sinclair/typemap'\n\n// Compile Zod Type\n\nconst validator = Compile(Zod(`{\n   x: number,\n   y: number,\n   z: number\n}`))\n\nconst R1 = validator.Check({ x: 1, y: 2, z: 3 })    // Accelerated\n\n// Standard Schema\n//\n// ... which should have been named 'Standard Validator'\n\nconst R2 = validator['~standard'].validate({ x: 1, y: 2, z: 3 })\n```\n\n## Benchmark\n\nThis project manages a small benchmark that compares validation performance using Zod, Valibot, and TypeBox validators. For more comprehensive community benchmarks, refer to the [runtime-type-benchmarks](https://github.com/moltar/typescript-runtime-type-benchmarks) project.\n\n### Test\n\nBenchmarks are run for the following type.\n\n```typescript\ntype T = { x: number, y: string, z: boolean }\n```\n\n### Results\n\nResults show the approximate elapsed time to complete the given iterations\n\n```typescript\n┌─────────┬────────────────┬────────────────────┬────────────┬────────────┐\n│ (index) │ library        │ using              │ iterations │ elapsed    │\n├─────────┼────────────────┼────────────────────┼────────────┼────────────┤\n│ 0       │ 'valibot     ' │ 'valibot         ' │ 10000000   │ '1534 ms ' │\n│ 1       │ 'valibot     ' │ 'typebox:value   ' │ 10000000   │ '1377 ms ' │\n│ 2       │ 'valibot     ' │ 'typebox:compile ' │ 10000000   │ '46 ms   ' │\n└─────────┴────────────────┴────────────────────┴────────────┴────────────┘\n┌─────────┬────────────────┬────────────────────┬────────────┬────────────┐\n│ (index) │ library        │ using              │ iterations │ elapsed    │\n├─────────┼────────────────┼────────────────────┼────────────┼────────────┤\n│ 0       │ 'zod         ' │ 'zod             ' │ 10000000   │ '4669 ms ' │\n│ 1       │ 'zod         ' │ 'typebox:value   ' │ 10000000   │ '1359 ms ' │\n│ 2       │ 'zod         ' │ 'typebox:compile ' │ 10000000   │ '47 ms   ' │\n└─────────┴────────────────┴────────────────────┴────────────┴────────────┘\n```\n\n\n\n## Contribute\n\nThis project is open to community contributions. Please ensure you submit an open issue before creating a pull request. TypeBox and associated projects preference open community discussion before accepting new features.\n\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Ftypemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairzx81%2Ftypemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Ftypemap/lists"}