<div align='center'>
<h1>TypeBox</h1>
<p>JSON Schema Type Builder with Static Type Resolution for TypeScript</p>
<img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
<br />
<br />
[![npm version](https://badge.fury.io/js/%40sinclair%2Ftypebox.svg)](https://badge.fury.io/js/%40sinclair%2Ftypebox)
[![Downloads](https://img.shields.io/npm/dm/%40sinclair%2Ftypebox.svg)](https://www.npmjs.com/package/%40sinclair%2Ftypebox)
[![GitHub CI](https://github.com/sinclairzx81/typebox/workflows/GitHub%20CI/badge.svg)](https://github.com/sinclairzx81/typebox/actions)
</div>
<a name="Install"></a>
## Install
#### Npm
```bash
$ npm install @sinclair/typebox --save
```
#### Deno
```typescript
import { Static, Type } from 'npm:@sinclair/typebox'
```
#### Esm
```typescript
import { Static, Type } from 'https://esm.sh/@sinclair/typebox'
```
## Example
```typescript
import { Static, Type } from '@sinclair/typebox'
const T = Type.Object({ // const T = {
x: Type.Number(), // type: 'object',
y: Type.Number(), // required: ['x', 'y', 'z'],
z: Type.Number() // properties: {
}) // x: { type: 'number' },
// y: { type: 'number' },
// z: { type: 'number' }
// }
// }
type T = Static<typeof T> // type T = {
// x: number,
// y: number,
// z: number
// }
```
<a name="Overview"></a>
## Overview
TypeBox is a runtime type builder that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
License MIT
## Contents
- [Install](#install)
- [Overview](#overview)
- [Usage](#usage)
- [Types](#types)
- [Standard](#types-standard)
- [Extended](#types-extended)
- [Modifiers](#types-modifiers)
- [Options](#types-options)
- [Generics](#types-generics)
- [References](#types-references)
- [Recursive](#types-recursive)
- [Conditional](#types-conditional)
- [Template Literal](#types-template-literal)
- [Guards](#types-guards)
- [Unsafe](#types-unsafe)
- [Strict](#types-strict)
- [Values](#values)
- [Create](#values-create)
- [Clone](#values-clone)
- [Check](#values-check)
- [Convert](#values-convert)
- [Cast](#values-cast)
- [Equal](#values-equal)
- [Hash](#values-hash)
- [Diff](#values-diff)
- [Patch](#values-patch)
- [Errors](#values-errors)
- [Mutate](#values-mutate)
- [Pointer](#values-pointer)
- [TypeCheck](#typecheck)
- [Ajv](#typecheck-ajv)
- [TypeCompiler](#typecheck-typecompiler)
- [TypeSystem](#typesystem)
- [Types](#typesystem-types)
- [Formats](#typesystem-formats)
- [Policies](#typesystem-policies)
- [Benchmark](#benchmark)
- [Compile](#benchmark-compile)
- [Validate](#benchmark-validate)
- [Compression](#benchmark-compression)
- [Contribute](#contribute)
<a name="usage"></a>
## Usage
The following shows general usage.
```typescript
import { Static, Type } from '@sinclair/typebox'
//--------------------------------------------------------------------------------------------
//
// Let's say you have the following type ...
//
//--------------------------------------------------------------------------------------------
type T = {
id: string,
name: string,
timestamp: number
}
//--------------------------------------------------------------------------------------------
//
// ... you can express this type in the following way.
//
//--------------------------------------------------------------------------------------------
const T = Type.Object({ // const T = {
id: Type.String(), // type: 'object',
name: Type.String(), // properties: {
timestamp: Type.Integer() // id: {
}) // type: 'string'
// },
// name: {
// type: 'string'
// },
// timestamp: {
// type: 'integer'
// }
// },
// required: [
// 'id',
// 'name',
// 'timestamp'
// ]
// }
//--------------------------------------------------------------------------------------------
//
// ... then infer back to the original static type this way.
//
//--------------------------------------------------------------------------------------------
type T = Static<typeof T> // type T = {
// id: string,
// name: string,
// timestamp: number
// }
//--------------------------------------------------------------------------------------------
//
// ... then use the type both as JSON schema and as a TypeScript type.
//
//--------------------------------------------------------------------------------------------
import { Value } from '@sinclair/typebox/value'
function receive(value: T) { // ... as a Static Type
if(Value.Check(T, value)) { // ... as a JSON Schema
// ok...
}
}
```
<a name='types'></a>
## Types
TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
<a name='types-standard'></a>
### Standard Types
The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema Draft 6 specification.
```typescript
┌────────────────────────────────┬─────────
没有合适的资源?快使用搜索试试~ 我知道了~
vue3+vite 组件打包
共2000个文件
js:1511个
md:303个
json:168个
需积分: 0 0 下载量 3 浏览量
2024-04-16
18:11:15
上传
评论
收藏 19.99MB ZIP 举报
温馨提示
vue3+vite 组件打包
资源推荐
资源详情
资源评论
收起资源包目录
vue3+vite 组件打包 (2000个子文件)
index-4C1OrvPf.css 59KB
style.css 791B
browser-example.html 2KB
index.html 931B
index-l-uvQjy0.js 3.86MB
rollup.js 784KB
node-entry.js 783KB
cac.RvTIWZBK.js 583KB
vue.global.js 507KB
vue.esm-browser.js 477KB
chai.js 361KB
vue.runtime.global.js 346KB
chunk-2FDUVFJ5.js 328KB
vue.runtime.esm-browser.js 321KB
beautifier.js 222KB
index.e9RDLAeW.js 196KB
psl.js 158KB
vue-router.global.js 155KB
vue.esm-browser.prod.js 147KB
beautify.js 146KB
vue.global.prod.js 144KB
vue-router.esm-browser.js 142KB
psl.min.js 134KB
assertions.js 132KB
watch.js 128KB
index.js 119KB
index.js 113KB
index.js 112KB
vi.JYQecGiw.js 111KB
beautify-html.js 111KB
index.js 104KB
index.js 103KB
diff.worker-IXaBev30.js 99KB
index.xL8XjTLv.js 98KB
beautifier.min.js 97KB
typebox.js 97KB
vue-router.js 95KB
parseAst.js 92KB
assert.js 91KB
vue.runtime.esm-browser.prod.js 89KB
vue.runtime.global.prod.js 88KB
main.js 87KB
parseAst.js 84KB
saxes.js 72KB
command.js 68KB
regexes.js 67KB
index.js 64KB
index.js 63KB
nwsapi.js 63KB
beautifier.js 56KB
beautify-css.js 53KB
index.js 50KB
index.js 50KB
speakingurl.js 39KB
beautifier.js 37KB
errors.js 34KB
index.js 33KB
index.js 33KB
index.js 32KB
sbcs-data-generated.js 31KB
index.js 31KB
url-state-machine.js 30KB
features.js 30KB
Window.js 30KB
loupe.js 28KB
parse.js 27KB
index.js 27KB
compiler.js 26KB
trace-mapping.umd.js 25KB
cli.js 25KB
cli.js 25KB
vue-router.global.prod.js 24KB
vm.cAHVDF92.js 24KB
dbcs-codec.js 23KB
loadConfigFile.js 21KB
execute.2_yoIC01.js 21KB
url-parse.js 21KB
agents.js 20KB
index-1IineNRs.js 20KB
tokenizer.js 20KB
check.js 19KB
watch-cli.js 19KB
cast.js 18KB
index.js 18KB
beautifier.js 18KB
html.js 18KB
html.js 17KB
create.js 17KB
URLSearchParams.js 17KB
index.js 16KB
index.GVFv9dZ0.js 16KB
index.js 16KB
convert.js 16KB
tests.js 15KB
speakingurl.min.js 15KB
parser.js 14KB
index.js 14KB
default-stylesheet.js 14KB
range.js 14KB
URL.js 14KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
前端小小小学生
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功