<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 />
[](https://badge.fury.io/js/%40sinclair%2Ftypebox)
[](https://www.npmjs.com/package/%40sinclair%2Ftypebox)
[](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
┌────────────────────────────────┬─────────
没有合适的资源?快使用搜索试试~ 我知道了~
three+vite开发demo

共2000个文件
js:1209个
md:650个
json:135个

需积分: 2 0 下载量 15 浏览量
2024-01-19
14:01:21
上传
评论
收藏 23.57MB 7Z 举报
温馨提示
This template should help get you started developing with Vue 3 in Vite. ```sh npm install ``` ### Compile and Hot-Reload for Development ```sh npm run dev ``` ### Type-Check, Compile and Minify for Production ```sh npm run build ``` ### Run Unit Tests with [Vitest](https://vitest.dev/) ```sh npm run test:unit ``` ### Lint with [ESLint](https://eslint.org/) ```sh npm run lint ```
资源推荐
资源详情
资源评论





















收起资源包目录





































































































共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论


Dream_travelerly
- 粉丝: 286
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于COP2000的模型机研究和简单编程.doc
- “上应小风筝”小程序 API 代码和文档, 基于 Rust 语言的 tonic 框架编写
- 9种网盘高效使用技巧全攻略
- rometheus监控elasticsearch,prometheus监控kafka,prometheus监控mysql,prometheus监控redis,prometheus监控非云原生应用
- E22系列无线模块通常使用特定的指令来配置信道
- 手写数字图像分割+识别
- 米尚服饰网络推广方案与计划------.pdf
- 大数据技术与应用专业申请书.doc
- 中鸡镇幼儿园网络研修与校本研修整合工作方案.doc
- cadence16.6差分约束规则.docx
- 软件测试员个人简历模板.docx
- 东莞码头泊位运营管理软件系统技术规格书.doc
- 新经济时代的微软.pptx
- 网络营销的定义及特征.pptx
- 中德网民网络购物行为比较.doc
- 电气与PLC控制系统的设计安装调试与维护.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
