{"name":"@sinclair/typebox","version":"0.24.15","keywords":["json-schema","typescript","static-types","runtime-typechecking"],"author":{"name":"sinclairzx81"},"license":"MIT","_id":"@sinclair/typebox@0.24.15","homepage":"https://github.com/sinclairzx81/typebox#readme","bugs":{"url":"https://github.com/sinclairzx81/typebox/issues"},"dist":{"shasum":"423bc636cf47d039aa79f20cf5fc248576931290","tarball":"http://registry-npm.ywwl.com/@sinclair/typebox/download/@sinclair/typebox-0.24.15.tgz","fileCount":31,"integrity":"sha512-VtII20dRdDzJy7hk9Zh2u8wbNhFeOm7P8S9dpVIagkP7cJLDeOP5YRdSWbiZF29nkxFXhI6Axj/pZbRkT2lTTg==","signatures":[{"sig":"MEYCIQCCJqe7yf+NS7qjFz4r2NE/EVV8A5BzhjS3yCwvZG+eywIhALqtE9sU0QoXzsGYRvcL6nwi+IIjPHAxV90q18F/efvD","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":234352,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiyv/fACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrVww//dH2o5oAFEGIJ4LiJpJUHlOQkZ4Gymx4rq10OzthyN8hIreyc\r\nTArwdMwLdSdKgFqDmrf3ucnwwENNySnB/3YWtiAJhBTpErYB91Bll+OLDt1e\r\noMWzeHRl8CFNPH07dw5ShSGdA/BXBbLpAc7Qj6bfxwdyuKgvV80E24EEFtPy\r\nd4udTJm+Lt4dqF+0YF/0k7IBFH62u1n2+5SQAzN5C6IXxjksT9K8jvyrIwIf\r\nA5Q4Be95mrIDfWRph0SMYlK8eUd2+z05+Mos0/wLFtajOewxQc0PAsUkU0Og\r\nRRWDJc73WfFggnp9DmnwQaXU1fyeTRNtKkEh7uuFZ41YRZ5gTMhunCniLnu4\r\nEs8DlPJIHAYr2xWGSN/1oIm9oq9m3UeF/99ej0tLkdRn7od27fOQJcJqbCR5\r\nxJAVaI84yXwgUgXP5DxwcmKNJi3wQucrq82CysPRa389EPqnZYF/dxeNgsjU\r\nhgosxFeDCDQsfFVA7Xpq3OlSuADtbkLMjA4U8xduuA9uq03WEkV7YA56Iyp+\r\nbFtCiHOmfn986zZBYAm/VKGGsPYSGgVPiJvggqCx/baKnEDV4f9VOcou1nkD\r\nno5qKmDfsTxICoZbU5kv2UxgzLkIGtlhErXLbTR0u2VZHwDk6NCC4qOzJ0Y8\r\nUMgFWc7leValyjmat8/jyKtjjXsyduN26lc=\r\n=3yOv\r\n-----END PGP SIGNATURE-----\r\n","size":29186,"noattachment":false,"key":"/@sinclair/typebox/-/@sinclair/typebox-0.24.15.tgz"},"main":"./typebox.js","_from":"file:sinclair-typebox-0.24.15.tgz","types":"./typebox.d.ts","scripts":{"test":"hammer task test","build":"hammer task build","clean":"hammer task clean","start":"hammer task start","format":"hammer task format","publish":"hammer task publish","benchmark":"hammer task benchmark"},"_npmUser":{"name":"sinclair","email":"haydn.developer@gmail.com"},"_resolved":"C:\\Users\\relay\\Desktop\\typebox\\target\\build\\sinclair-typebox-0.24.15.tgz","_integrity":"sha512-VtII20dRdDzJy7hk9Zh2u8wbNhFeOm7P8S9dpVIagkP7cJLDeOP5YRdSWbiZF29nkxFXhI6Axj/pZbRkT2lTTg==","repository":{"url":"git+https://github.com/sinclairzx81/typebox.git","type":"git"},"_npmVersion":"8.12.1","description":"JSONSchema Type Builder with Static Type Resolution for TypeScript","directories":{},"_nodeVersion":"18.4.0","_hasShrinkwrap":false,"devDependencies":{"ajv":"^8.11.0","tsd":"^0.19.1","chai":"^4.3.5","mocha":"^9.2.0","prettier":"^2.7.1","typescript":"^4.7.4","@types/chai":"^4.3.0","@types/node":"^17.0.12","ajv-formats":"^2.1.1","@types/mocha":"^9.1.0","@sinclair/hammer":"^0.16.3"},"_npmOperationalInternal":{"tmp":"tmp/typebox_0.24.15_1657470943181_0.23398543355131052","host":"s3://npm-registry-packages"},"readme":"<div align='center'>\r\n\r\n<h1>TypeBox</h1>\r\n\r\n<p>Json Schema Type Builder with Static Type Resolution for TypeScript</p>\r\n\r\n<img src=\"https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true\" />\r\n\r\n<br />\r\n<br />\r\n\r\n[![npm version](https://badge.fury.io/js/%40sinclair%2Ftypebox.svg)](https://badge.fury.io/js/%40sinclair%2Ftypebox)\r\n[![Downloads](https://img.shields.io/npm/dm/%40sinclair%2Ftypebox.svg)](https://www.npmjs.com/package/%40sinclair%2Ftypebox)\r\n[![Build](https://github.com/sinclairzx81/typebox/actions/workflows/build.yml/badge.svg)](https://github.com/sinclairzx81/typebox/actions/workflows/build.yml)\r\n[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n</div>\r\n\r\n<a name=\"Install\"></a>\r\n\r\n## Install\r\n\r\n```bash\r\n$ npm install @sinclair/typebox --save\r\n```\r\n\r\n## Example\r\n\r\n```typescript\r\nimport { Type, type Static } from '@sinclair/typebox'\r\n\r\nconst T = Type.Object({                              // const T = {\r\n  x: Type.Number(),                                  //   type: 'object',\r\n  y: Type.Number(),                                  //   required: ['x', 'y', 'z'],\r\n  z: Type.Number()                                   //   properties: {\r\n})                                                   //     x: { type: 'number' },\r\n                                                     //     y: { type: 'number' },\r\n                                                     //     z: { type: 'number' }\r\n                                                     //   }\r\n                                                     // }\r\n\r\ntype T = Static<typeof T>                            // type T = {\r\n                                                     //   x: number,\r\n                                                     //   y: number,\r\n                                                     //   z: number\r\n                                                     // }\r\n```\r\n\r\n\r\n<a name=\"Overview\"></a>\r\n\r\n## Overview\r\n\r\nTypeBox is a runtime type builder that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript and runtime asserted using standard Json Schema validation.\r\n\r\nThis library is designed to allow Json Schema to compose similar to how types compose within TypeScript's type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.\r\n\r\nLicense MIT\r\n\r\n## Contents\r\n- [Install](#install)\r\n- [Overview](#overview)\r\n- [Usage](#usage)\r\n- [Types](#types)\r\n  - [Json](#types-json)\r\n  - [JavaScript](#types-javascript)\r\n  - [Import](#types-import)\r\n  - [Options](#types-options)\r\n  - [Properties](#types-properties)\r\n  - [Generics](#types-generics)\r\n  - [References](#types-references)\r\n  - [Recursive](#types-recursive)\r\n  - [Template Literal](#types-template-literal)\r\n  - [Indexed](#types-indexed)\r\n  - [Mapped](#types-mapped)\r\n  - [Conditional](#types-conditional)\r\n  - [Intrinsic](#types-intrinsic)\r\n  - [Transform](#types-transform)\r\n  - [Rest](#types-rest)\r\n  - [Guard](#types-guard)\r\n  - [Unsafe](#types-unsafe)\r\n  - [Strict](#types-strict)\r\n- [Values](#values)\r\n  - [Create](#values-create)\r\n  - [Clone](#values-clone)\r\n  - [Check](#values-check)\r\n  - [Convert](#values-convert)\r\n  - [Default](#values-default)\r\n  - [Clean](#values-clean)\r\n  - [Cast](#values-cast)\r\n  - [Decode](#values-decode)\r\n  - [Encode](#values-decode)\r\n  - [Equal](#values-equal)\r\n  - [Hash](#values-hash)\r\n  - [Diff](#values-diff)\r\n  - [Patch](#values-patch)\r\n  - [Errors](#values-errors)\r\n  - [Mutate](#values-mutate)\r\n  - [Pointer](#values-pointer)\r\n- [TypeRegistry](#typeregistry)\r\n  - [Type](#typeregistry-type)\r\n  - [Format](#typeregistry-format)\r\n- [TypeCheck](#typecheck)\r\n  - [Ajv](#typecheck-ajv)\r\n  - [TypeCompiler](#typecheck-typecompiler)\r\n- [TypeSystem](#typesystem)\r\n  - [Policies](#typesystem-policies)\r\n- [Error Function](#error-function)\r\n- [Workbench](#workbench)\r\n- [Codegen](#codegen)\r\n- [Ecosystem](#ecosystem)\r\n- [Benchmark](#benchmark)\r\n  - [Compile](#benchmark-compile)\r\n  - [Validate](#benchmark-validate)\r\n  - [Compression](#benchmark-compression)\r\n- [Contribute](#contribute)\r\n\r\n<a name=\"usage\"></a>\r\n\r\n## Usage\r\n\r\nThe following shows general usage.\r\n\r\n```typescript\r\nimport { Type, type Static } from '@sinclair/typebox'\r\n\r\n//--------------------------------------------------------------------------------------------\r\n//\r\n// Let's say you have the following type ...\r\n//\r\n//--------------------------------------------------------------------------------------------\r\n\r\ntype T = {\r\n  id: string,\r\n  name: string,\r\n  timestamp: number\r\n}\r\n\r\n//--------------------------------------------------------------------------------------------\r\n//\r\n// ... you can express this type in the following way.\r\n//\r\n//--------------------------------------------------------------------------------------------\r\n\r\nconst T = Type.Object({                              // const T = {\r\n  id: Type.String(),                                 //   type: 'object',\r\n  name: Type.String(),                               //   properties: {\r\n  timestamp: Type.Integer()                          //     id: {\r\n})                                                   //       type: 'string'\r\n                                                     //     },\r\n                                                     //     name: {\r\n                                                     //       type: 'string'\r\n                                                     //     },\r\n                                                     //     timestamp: {\r\n                                                     //       type: 'integer'\r\n                                                     //     }\r\n                                                     //   },\r\n                                                     //   required: [\r\n                                                     //     'id',\r\n                                                     //     'name',\r\n                                                     //     'timestamp'\r\n                                                     //   ]\r\n                                                     // }\r\n\r\n//--------------------------------------------------------------------------------------------\r\n//\r\n// ... then infer back to the original static type this way.\r\n//\r\n//--------------------------------------------------------------------------------------------\r\n\r\ntype T = Static<typeof T>                            // type T = {\r\n                                                     //   id: string,\r\n                                                     //   name: string,\r\n                                                     //   timestamp: number\r\n                                                     // }\r\n\r\n//--------------------------------------------------------------------------------------------\r\n//\r\n// ... then use the type both as Json Schema and as a TypeScript type.\r\n//\r\n//--------------------------------------------------------------------------------------------\r\n\r\nimport { Value } from '@sinclair/typebox/value'\r\n\r\nfunction receive(value: T) {                         // ... as a Static Type\r\n\r\n  if(Value.Check(T, value)) {                        // ... as a Json Schema\r\n\r\n    // ok...\r\n  }\r\n}\r\n```\r\n\r\n<a name='types'></a>\r\n\r\n## Types\r\n\r\nTypeBox types are Json Schema fragments that compose into more complex types. Each fragment is structured such that any Json Schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox offers a set of Json Types which are used to create Json Schema compliant schematics as well as a JavaScript type set used to create schematics for constructs native to JavaScript.\r\n\r\n<a name='types-json'></a>\r\n\r\n### Json Types\r\n\r\nThe following table lists the supported Json types. These types are fully compatible with the Json Schema Draft 7 specification.\r\n\r\n```typescript\r\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\r\n│ TypeBox                        │ TypeScript                  │ Json Schema                    │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Any()           │ type T = any                │ const T = { }                  │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Unknown()       │ type T = unknown            │ const T = { }                  │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.String()        │ type T = string             │ const T = {                    │\r\n│                                │                             │   type: 'string'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Number()        │ type T = number             │ const T = {                    │\r\n│                                │                             │   type: 'number'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Integer()       │ type T = number             │ const T = {                    │\r\n│                                │                             │   type: 'integer'              │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Boolean()       │ type T = boolean            │ const T = {                    │\r\n│                                │                             │   type: 'boolean'              │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Null()          │ type T = null               │ const T = {                    │\r\n│                                │                             │   type: 'null'                 │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Literal(42)     │ type T = 42                 │ const T = {                    │\r\n│                                │                             │   const: 42,                   │\r\n│                                │                             │   type: 'number'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Array(          │ type T = number[]           │ const T = {                    │\r\n│   Type.Number()                │                             │   type: 'array',               │\r\n│ )                              │                             │   items: {                     │\r\n│                                │                             │     type: 'number'             │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Object({        │ type T = {                  │ const T = {                    │\r\n│   x: Type.Number(),            │   x: number,                │   type: 'object',              │\r\n│   y: Type.Number()             │   y: number                 │   required: ['x', 'y'],        │\r\n│ })                             │ }                           │   properties: {                │\r\n│                                │                             │     x: {                       │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     },                         │\r\n│                                │                             │     y: {                       │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Tuple([         │ type T = [number, number]   │ const T = {                    │\r\n│   Type.Number(),               │                             │   type: 'array',               │\r\n│   Type.Number()                │                             │   items: [{                    │\r\n│ ])                             │                             │     type: 'number'             │\r\n│                                │                             │   }, {                         │\r\n│                                │                             │     type: 'number'             │\r\n│                                │                             │   }],                          │\r\n│                                │                             │   additionalItems: false,      │\r\n│                                │                             │   minItems: 2,                 │\r\n│                                │                             │   maxItems: 2                  │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ enum Foo {                     │ enum Foo {                  │ const T = {                    │\r\n│   A,                           │   A,                        │   anyOf: [{                    │\r\n│   B                            │   B                         │     type: 'number',            │\r\n│ }                              │ }                           │     const: 0                   │\r\n│                                │                             │   }, {                         │\r\n│ const T = Type.Enum(Foo)       │ type T = Foo                │     type: 'number',            │\r\n│                                │                             │     const: 1                   │\r\n│                                │                             │   }]                           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Const({         │ type T = {                  │ const T = {                    │\r\n│   x: 1,                        │   readonly x: 1,            │   type: 'object',              │\r\n│   y: 2,                        │   readonly y: 2             │   required: ['x', 'y'],        │\r\n│ } as const)                    │ }                           │   properties: {                │\r\n│                                │                             │     x: {                       │\r\n│                                │                             │       type: 'number',          │\r\n│                                │                             │       const: 1                 │\r\n│                                │                             │     },                         │\r\n│                                │                             │     y: {                       │\r\n│                                │                             │       type: 'number',          │\r\n│                                │                             │       const: 2                 │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.KeyOf(          │ type T = keyof {            │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   anyOf: [{                    │\r\n│     x: Type.Number(),          │   y: number                 │     type: 'string',            │\r\n│     y: Type.Number()           │ }                           │     const: 'x'                 │\r\n│   })                           │                             │   }, {                         │\r\n│ )                              │                             │     type: 'string',            │\r\n│                                │                             │     const: 'y'                 │\r\n│                                │                             │   }]                           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Union([         │ type T = string | number    │ const T = {                    │\r\n│   Type.String(),               │                             │   anyOf: [{                    │\r\n│   Type.Number()                │                             │     type: 'string'             │\r\n│ ])                             │                             │   }, {                         │\r\n│                                │                             │     type: 'number'             │\r\n│                                │                             │   }]                           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Intersect([     │ type T = {                  │ const T = {                    │\r\n│   Type.Object({                │   x: number                 │   allOf: [{                    │\r\n│     x: Type.Number()           │ } & {                       │     type: 'object',            │\r\n│   }),                          │   y: number                 │     required: ['x'],           │\r\n│   Type.Object({                │ }                           │     properties: {              │\r\n│     y: Type.Number()           │                             │       x: {                     │\r\n│   ])                           │                             │         type: 'number'         │\r\n│ ])                             │                             │       }                        │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }, {                         │\r\n│                                │                             │     type: 'object',            |\r\n│                                │                             │     required: ['y'],           │\r\n│                                │                             │     properties: {              │\r\n│                                │                             │       y: {                     │\r\n│                                │                             │         type: 'number'         │\r\n│                                │                             │       }                        │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }]                           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Composite([     │ type T = {                  │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   type: 'object',              │\r\n│     x: Type.Number()           │   y: number                 │   required: ['x', 'y'],        │\r\n│   }),                          │ }                           │   properties: {                │\r\n│   Type.Object({                │                             │     x: {                       │\r\n│     y: Type.Number()           │                             │       type: 'number'           │\r\n│   })                           │                             │     },                         │\r\n│ ])                             │                             │     y: {                       │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Never()         │ type T = never              │ const T = {                    │\r\n│                                │                             │   not: {}                      │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Not(            | type T = unknown            │ const T = {                    │\r\n│   Type.String()                │                             │   not: {                       │\r\n│ )                              │                             │     type: 'string'             │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Extends(        │ type T =                    │ const T = {                    │\r\n│   Type.String(),               │  string extends number      │   const: false,                │\r\n│   Type.Number(),               │    ? true                   │   type: 'boolean'              │\r\n│   Type.Literal(true),          │    : false                  │ }                              │\r\n│   Type.Literal(false)          │                             │                                │\r\n│ )                              │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Extract(        │ type T = Extract<           │ const T = {                    │\r\n│   Type.Union([                 │   string | number,          │   type: 'string'               │\r\n│     Type.String(),             │   string                    │ }                              │\r\n│     Type.Number(),             │ >                           │                                │\r\n│   ]),                          │                             │                                │\r\n│   Type.String()                │                             │                                │\r\n│ )                              │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Exclude(        │ type T = Exclude<           │ const T = {                    │\r\n│   Type.Union([                 │   string | number,          │   type: 'number'               │\r\n│     Type.String(),             │   string                    │ }                              │\r\n│     Type.Number(),             │ >                           │                                │\r\n│   ]),                          │                             │                                │\r\n│   Type.String()                │                             │                                │\r\n│ )                              │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Mapped(         │ type T = {                  │ const T = {                    │\r\n│   Type.Union([                 │   [_ in 'x' | 'y'] : number │   type: 'object',              │\r\n│     Type.Literal('x'),         │ }                           │   required: ['x', 'y'],        │\r\n│     Type.Literal('y')          │                             │   properties: {                │\r\n│   ]),                          │                             │     x: {                       │\r\n│   () => Type.Number()          │                             │       type: 'number'           │\r\n│ )                              │                             │     },                         │\r\n│                                │                             │     y: {                       │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const U = Type.Union([         │ type U = 'open' | 'close'   │ const T = {                    │\r\n│   Type.Literal('open'),        │                             │   type: 'string',              │\r\n│   Type.Literal('close')        │ type T = `on${U}`           │   pattern: '^on(open|close)$'  │\r\n│ ])                             │                             │ }                              │\r\n│                                │                             │                                │\r\n│ const T = Type                 │                             │                                │\r\n│   .TemplateLiteral([           │                             │                                │\r\n│      Type.Literal('on'),       │                             │                                │\r\n│      U                         │                             │                                │\r\n│   ])                           │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Record(         │ type T = Record<            │ const T = {                    │\r\n│   Type.String(),               │   string,                   │   type: 'object',              │\r\n│   Type.Number()                │   number                    │   patternProperties: {         │\r\n│ )                              │ >                           │     '^.*$': {                  │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Partial(        │ type T = Partial<{          │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   type: 'object',              │\r\n│     x: Type.Number(),          │   y: number                 │   properties: {                │\r\n│     y: Type.Number()           | }>                          │     x: {                       │\r\n│   })                           │                             │       type: 'number'           │\r\n│ )                              │                             │     },                         │\r\n│                                │                             │     y: {                       │\r\n│                                │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Required(       │ type T = Required<{         │ const T = {                    │\r\n│   Type.Object({                │   x?: number,               │   type: 'object',              │\r\n│     x: Type.Optional(          │   y?: number                │   required: ['x', 'y'],        │\r\n│       Type.Number()            | }>                          │   properties: {                │\r\n│     ),                         │                             │     x: {                       │\r\n│     y: Type.Optional(          │                             │       type: 'number'           │\r\n│       Type.Number()            │                             │     },                         │\r\n│     )                          │                             │     y: {                       │\r\n│   })                           │                             │       type: 'number'           │\r\n│ )                              │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Pick(           │ type T = Pick<{             │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   type: 'object',              │\r\n│     x: Type.Number(),          │   y: number                 │   required: ['x'],             │\r\n│     y: Type.Number()           │ }, 'x'>                     │   properties: {                │\r\n│   }), ['x']                    |                             │     x: {                       │\r\n│ )                              │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Omit(           │ type T = Omit<{             │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   type: 'object',              │\r\n│     x: Type.Number(),          │   y: number                 │   required: ['y'],             │\r\n│     y: Type.Number()           │ }, 'x'>                     │   properties: {                │\r\n│   }), ['x']                    |                             │     y: {                       │\r\n│ )                              │                             │       type: 'number'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Index(          │ type T = {                  │ const T = {                    │\r\n│   Type.Object({                │   x: number,                │   type: 'number'               │\r\n│     x: Type.Number(),          │   y: string                 │ }                              │\r\n│     y: Type.String()           │ }['x']                      │                                │\r\n│   }), ['x']                    │                             │                                │\r\n│ )                              │                             │                                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const A = Type.Tuple([         │ type A = [0, 1]             │ const T = {                    │\r\n│   Type.Literal(0),             │ type B = [2, 3]             │   type: 'array',               │\r\n│   Type.Literal(1)              │ type T = [                  │   items: [                     │\r\n│ ])                             │   ...A,                     │     { const: 0 },              │\r\n│ const B = Type.Tuple([         │   ...B                      │     { const: 1 },              │\r\n|   Type.Literal(2),             │ ]                           │     { const: 2 },              │\r\n|   Type.Literal(3)              │                             │     { const: 3 }               │\r\n│ ])                             │                             │   ],                           │\r\n│ const T = Type.Tuple([         │                             │   additionalItems: false,      │\r\n|   ...Type.Rest(A),             │                             │   minItems: 4,                 │\r\n|   ...Type.Rest(B)              │                             │   maxItems: 4                  │\r\n│ ])                             │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Uncapitalize(   │ type T = Uncapitalize<      │ const T = {                    │\r\n│   Type.Literal('Hello')        │   'Hello'                   │   type: 'string',              │\r\n│ )                              │ >                           │   const: 'hello'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Capitalize(     │ type T = Capitalize<        │ const T = {                    │\r\n│   Type.Literal('hello')        │   'hello'                   │   type: 'string',              │\r\n│ )                              │ >                           │   const: 'Hello'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Uppercase(      │ type T = Uppercase<         │ const T = {                    │\r\n│   Type.Literal('hello')        │   'hello'                   │   type: 'string',              │\r\n│ )                              │ >                           │   const: 'HELLO'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Lowercase(      │ type T = Lowercase<         │ const T = {                    │\r\n│   Type.Literal('HELLO')        │   'HELLO'                   │   type: 'string',              │\r\n│ )                              │ >                           │   const: 'hello'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Object({        │ type T = {                  │ const R = {                    │\r\n│    x: Type.Number(),           │   x: number,                │   $ref: 'T'                    │\r\n│    y: Type.Number()            │   y: number                 │ }                              │\r\n│ }, { $id: 'T' })               | }                           │                                │\r\n│                                │                             │                                │\r\n│ const R = Type.Ref(T)          │ type R = T                  │                                │\r\n│                                │                             │                                │\r\n│                                │                             │                                │\r\n│                                │                             │                                │\r\n│                                │                             │                                │\r\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\r\n```\r\n\r\n<a name='types-javascript'></a>\r\n\r\n### JavaScript Types\r\n\r\nTypeBox provides an extended type set that can be used to create schematics for common JavaScript constructs. These types can not be used with any standard Json Schema validator; but can be used to frame schematics for interfaces that may receive Json validated data. JavaScript types are prefixed with the `[JavaScript]` jsdoc comment for convenience. The following table lists the supported types.\r\n\r\n```typescript\r\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\r\n│ TypeBox                        │ TypeScript                  │ Extended Schema                │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Constructor([   │ type T = new (              │ const T = {                    │\r\n│   Type.String(),               │  arg0: string,              │   type: 'Constructor',         │\r\n│   Type.Number()                │  arg0: number               │   parameters: [{               │\r\n│ ], Type.Boolean())             │ ) => boolean                │     type: 'string'             │\r\n│                                │                             │   }, {                         │\r\n│                                │                             │     type: 'number'             │\r\n│                                │                             │   }],                          │\r\n│                                │                             │   returns: {                   │\r\n│                                │                             │     type: 'boolean'            │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Function([      │ type T = (                  │ const T = {                    │\r\n|   Type.String(),               │  arg0: string,              │   type: 'Function',            │\r\n│   Type.Number()                │  arg1: number               │   parameters: [{               │\r\n│ ], Type.Boolean())             │ ) => boolean                │     type: 'string'             │\r\n│                                │                             │   }, {                         │\r\n│                                │                             │     type: 'number'             │\r\n│                                │                             │   }],                          │\r\n│                                │                             │   returns: {                   │\r\n│                                │                             │     type: 'boolean'            │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Promise(        │ type T = Promise<string>    │ const T = {                    │\r\n│   Type.String()                │                             │   type: 'Promise',             │\r\n│ )                              │                             │   item: {                      │\r\n│                                │                             │     type: 'string'             │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T =                      │ type T =                    │ const T = {                    │\r\n│   Type.AsyncIterator(          │   AsyncIterableIterator<    │   type: 'AsyncIterator',       │\r\n│     Type.String()              │    string                   │   items: {                     │\r\n│   )                            │   >                         │     type: 'string'             │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Iterator(       │ type T =                    │ const T = {                    │\r\n│   Type.String()                │   IterableIterator<string>  │   type: 'Iterator',            │\r\n│ )                              │                             │   items: {                     │\r\n│                                │                             │     type: 'string'             │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.RegExp(/abc/i)  │ type T = string             │ const T = {                    │\r\n│                                │                             │   type: 'RegExp'               │\r\n│                                │                             │   source: 'abc'                │\r\n│                                │                             │   flags: 'i'                   │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Uint8Array()    │ type T = Uint8Array         │ const T = {                    │\r\n│                                │                             │   type: 'Uint8Array'           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Date()          │ type T = Date               │ const T = {                    │\r\n│                                │                             │   type: 'Date'                 │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Undefined()     │ type T = undefined          │ const T = {                    │\r\n│                                │                             │   type: 'undefined'            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Symbol()        │ type T = symbol             │ const T = {                    │\r\n│                                │                             │   type: 'symbol'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.BigInt()        │ type T = bigint             │ const T = {                    │\r\n│                                │                             │   type: 'bigint'               │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Void()          │ type T = void               │ const T = {                    │\r\n│                                │                             │   type: 'void'                 │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\r\n```\r\n\r\n<a name='types-import'></a>\r\n\r\n### Import\r\n\r\nImport the Type namespace to bring in the full TypeBox type system. This is recommended for most users.\r\n\r\n```typescript\r\nimport { Type, type Static } from '@sinclair/typebox'\r\n```\r\n\r\nYou can also selectively import types. This enables modern bundlers to tree shake for unused types.\r\n\r\n```typescript\r\nimport { Object, Number, String, Boolean, type Static } from '@sinclair/typebox'\r\n```\r\n\r\n<a name='types-options'></a>\r\n\r\n### Options\r\n\r\nYou can pass Json Schema options on the last argument of any given type. Option hints specific to each type are provided for convenience.\r\n\r\n```typescript\r\n// String must be an email\r\nconst T = Type.String({                              // const T = {\r\n  format: 'email'                                    //   type: 'string',\r\n})                                                   //   format: 'email'\r\n                                                     // }\r\n\r\n// Number must be a multiple of 2\r\nconst T = Type.Number({                              // const T = {\r\n  multipleOf: 2                                      //  type: 'number',\r\n})                                                   //  multipleOf: 2\r\n                                                     // }\r\n\r\n// Array must have at least 5 integer values\r\nconst T = Type.Array(Type.Integer(), {               // const T = {\r\n  minItems: 5                                        //   type: 'array',\r\n})                                                   //   minItems: 5,\r\n                                                     //   items: {\r\n                                                     //     type: 'integer'\r\n                                                     //   }\r\n                                                     // }\r\n```\r\n\r\n<a name='types-properties'></a>\r\n\r\n### Properties\r\n\r\nObject properties can be modified with Readonly and Optional. The following table shows how these modifiers map between TypeScript and Json Schema.\r\n\r\n```typescript\r\n┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐\r\n│ TypeBox                        │ TypeScript                  │ Json Schema                    │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Object({        │ type T = {                  │ const T = {                    │\r\n│   name: Type.ReadonlyOptional( │   readonly name?: string    │   type: 'object',              │\r\n│     Type.String()              │ }                           │   properties: {                │\r\n│   )                            │                             │     name: {                    │\r\n│ })  \t                         │                             │       type: 'string'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Object({        │ type T = {                  │ const T = {                    │\r\n│   name: Type.Readonly(         │   readonly name: string     │   type: 'object',              │\r\n│     Type.String()              │ }                           │   properties: {                │\r\n│   )                            │                             │     name: {                    │\r\n│ })  \t                         │                             │       type: 'string'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   },                           │\r\n│                                │                             │   required: ['name']           │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤\r\n│ const T = Type.Object({        │ type T = {                  │ const T = {                    │\r\n│   name: Type.Optional(         │   name?: string             │   type: 'object',              │\r\n│     Type.String()              │ }                           │   properties: {                │\r\n│   )                            │                             │     name: {                    │\r\n│ })  \t                         │                             │       type: 'string'           │\r\n│                                │                             │     }                          │\r\n│                                │                             │   }                            │\r\n│                                │                             │ }                              │\r\n│                                │                             │                                │\r\n└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘\r\n```\r\n\r\n<a name='types-generics'></a>\r\n\r\n### Generic Types\r\n\r\nGeneric types can be created with functions. TypeBox types extend the TSchema interface so you should constrain parameters to this type. The following creates a generic Vector type.\r\n\r\n```typescript\r\nimport { Type, type Static, type TSchema } from '@sinclair/typebox'\r\n\r\nconst Vector = <T extends TSchema>(T: T) => \r\n  Type.Object({                                      // type Vector<T> = {\r\n    x: T,                                            //   x: T,\r\n    y: T,                                            //   y: T,\r\n    z: T                                             //   z: T\r\n  })                                                 // }\r\n\r\nconst NumberVector = Vector(Type.Number())           // type NumberVector = Vector<number>\r\n```\r\n\r\nGeneric types are often used to create aliases for complex types. The following creates a Nullable generic type.\r\n\r\n```typescript\r\nconst Nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()])\r\n\r\nconst T = Nullable(Type.String())                    // const T = {\r\n                                                     //   anyOf: [\r\n                                                     //     { type: 'string' },\r\n                                                     //     { type: 'null' }\r\n                                                     //   ]\r\n                                                     // }\r\n\r\ntype T = Static<typeof T>                            // type T = string | null\r\n```\r\n\r\n<a name='types-references'></a>\r\n\r\n### Reference Types\r\n\r\nReference types can be created with Ref. These types infer the same as the target type but only store a named `$ref` to the target type.\r\n\r\n```typescript\r\nconst Vector = Type.Object({                         // const Vector = {\r\n  x: Type.Number(),                                  //   type: 'object',\r\n  y: Type.Number(),                                  //   required: ['x', 'y', 'z'],\r\n}, { $id: 'Vector' })                                //   properties: {\r\n                                                     //     x: { type: 'number' },\r\n                                                     //     y: { type: 'number' }\r\n                                                     //   },\r\n                                                     //   $id: 'Vector'\r\n                                                     // }\r\n\r\nconst VectorRef = Type.Ref(Vector)                   // const VectorRef = {\r\n                                                     //   $ref: 'Vector'\r\n                                                     // }\r\n\r\ntype VectorRef = Static<typeof VectorRef>            // type VectorRef = {\r\n                                                     //    x: number,\r\n                                                     //    y: number\r\n                                                     // }\r\n```\r\nUse Deref to dereference a type. This function will replace any interior reference with the target type.\r\n```typescript\r\nconst Vertex = Type.Object({                         // const Vertex = {\r\n  position: VectorRef,                               //   type: 'object',\r\n  texcoord: VectorRef,                               //   required: ['position', 'texcoord'],\r\n})                                                   //   properties: {\r\n                                                     //     position: { $ref: 'Vector' },\r\n                                                     //     texcoord: { $ref: 'Vector' }\r\n                                                     //   }\r\n                                                     // }\r\n\r\nconst VertexDeref = Type.Deref(Vertex, [Vector])     // const VertexDeref = {\r\n                                                     //   type: 'object',\r\n                                                     //   required: ['position', 'texcoord'],\r\n                                                     //   properties: {\r\n                                                     //     position: {\r\n                                                     //       type: 'object',\r\n                                                     //       required: ['x', 'y', 'z'],\r\n                                                     //       properties: {\r\n                                                     //         x: { type: 'number' },\r\n                                                     //         y: { type: 'number' }\r\n                                                     //       }\r\n                                                     //     },\r\n                                                     //     texcoord: {\r\n                                                     //       type: 'object',\r\n                                                     //       required: ['x', 'y', 'z'],\r\n                                                     //       properties: {\r\n                                                     //         x: { type: 'number' },\r\n                                                     //         y: { type: 'number' }\r\n                                                     //       }\r\n                                                     //     }\r\n                                                     //   }\r\n                                                     // }\r\n```\r\nNote that Ref types do not store structural information about the type they're referencing. Because of this, these types cannot be used with some mapping types (such as Partial or Pick). For applications that require mapping on Ref, use Deref to normalize the type first.\r\n\r\n<a name='types-recursive'></a>\r\n\r\n### Recursive Types\r\n\r\nTypeBox supports recursive data structures with Recursive. This type wraps an interior type and provides it a `this` context that allows the type to reference itself. The following creates a recursive type. Singular recursive inference is also supported.\r\n\r\n```typescript\r\nconst Node = Type.Recursive(This => Type.Object({    // const Node = {\r\n  id: Type.String(),                                 //   $id: 'Node',\r\n  nodes: Type.Array(This)                            //   type: 'object',\r\n}), { $id: 'Node' })                                 //   properties: {\r\n                                                     //     id: {\r\n                                                     //       type: 'string'\r\n                                                     //     },\r\n                                                     //     nodes: {\r\n                                                     //       type: 'array',\r\n                                                     //       items: {\r\n                                                     //         $ref: 'Node'\r\n                                                     //       }\r\n                                                     //     }\r\n                                                     //   },\r\n                                                     //   required: [\r\n                                                     //     'id',\r\n                                                     //     'nodes'\r\n                                                     //   ]\r\n                                                     // }\r\n\r\ntype Node = Static<typeof Node>                      // type Node = {\r\n                                                     //   id: string\r\n                                                     //   nodes: Node[]\r\n                                                     // }\r\n\r\nfunction test(node: Node) {\r\n  const id = node.nodes[0].nodes[0].id               // id is string\r\n}\r\n```\r\n\r\n<a name='types-template-literal'></a>\r\n\r\n### Template Literal Types\r\n\r\nTypeBox supports template literal types with the TemplateLiteral function. This type can be created using a syntax similar to the TypeScript template literal syntax or composed from exterior types. TypeBox encodes template literals as regular expressions which enables the template to be checked by Json Schema validators. This type also supports regular expression parsing that enables template patterns to be used for generative types. The following shows both TypeScript and TypeBox usage.\r\n\r\n```typescript\r\n// TypeScript\r\n\r\ntype K = `prop${'A'|'B'|'C'}`                        // type T = 'propA' | 'propB' | 'propC'\r\n\r\ntype R = Record<K, string>                           // type R = {\r\n                                                     //   propA: string\r\n                                                     //   propB: string\r\n                                                     //   propC: string\r\n                                                     // }\r\n\r\n// TypeBox\r\n\r\nconst K = Type.TemplateLiteral('prop${A|B|C}')       // const K: TTemplateLiteral<[\r\n                                                     //   TLiteral<'prop'>,\r\n                               ","publish_time":1657470943421,"maintainers":[{"name":"sinclair","email":"haydn.developer@gmail.com"}],"_cnpm_publish_time":1657470943421,"dist-tags":{"dev":"0.32.0-dev-28","latest":"0.34.52","legacy-0.24":"0.24.52","legacy-0.25":"0.25.25","legacy-0.26":"0.26.9","legacy-0.27":"0.27.12","legacy-0.28":"0.28.22","legacy-0.29":"0.29.8","legacy-0.30":"0.30.6","legacy-0.31":"0.31.30","legacy-0.32":"0.32.37","legacy-0.33":"0.33.24"}}