<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) [![GitHub CI](https://github.com/sinclairzx81/typebox/workflows/GitHub%20CI/badge.svg)](https://github.com/sinclairzx81/typebox/actions)
</div>
<a name="Install"></a>
## Install
#### Node
```bash
$ npm install @sinclair/typebox --save
```
#### Deno
```typescript
import { Static, Type } from 'https://deno.land/x/typebox/src/typebox.ts'
```
## Example
```typescript
import { Static, Type } from '@sinclair/typebox'
const T = Type.String() // const T = { "type": "string" }
type T = Static<typeof T> // type T = string
```
<a name="Overview"></a>
## Overview
TypeBox is a library 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 checking rules of the TypeScript compiler. TypeBox allows one to create a unified type that can be both statically asserted by the TypeScript compiler and runtime asserted using standard JSON Schema validation.
TypeBox can be used as a simple tool to build up complex schemas or integrated into RPC or REST services to help validate JSON data received over the wire. TypeBox does not provide any JSON schema validation. Please use libraries such as AJV to validate schemas built with this library.
Requires TypeScript 4.3.5 and above.
License MIT
## Contents
- [Install](#Install)
- [Overview](#Overview)
- [Usage](#Usage)
- [Types](#Types)
- [Modifiers](#Modifiers)
- [Options](#Options)
- [Generic Types](#Generic-Types)
- [Reference Types](#Reference-Types)
- [Recursive Types](#Recursive-Types)
- [Extended Types](#Extended-Types)
- [Strict](#Strict)
- [Validation](#Validation)
- [OpenAPI](#OpenAPI)
<a name="Example"></a>
## Usage
The following demonstrates TypeBox's 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.
//
//--------------------------------------------------------------------------------------------
function receive(value: T) { // ... as a Type
if(JSON.validate(T, value)) { // ... as a Schema
// ok...
}
}
```
<a name="Types"></a>
## Types
The following table outlines the TypeBox mappings between TypeScript and JSON schema.
```typescript
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
│ TypeBox │ TypeScript │ JSON Schema │
│ │ │ │
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
│ const T = Type.Any() │ type T = any │ const T = { } │
│ │ │ │
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
│ const T = Type.Unknown() │ type T = unknown │ const T = { } │
│ │ │ │
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
│ const T = Type.String() │ type T = string │ const T = { │
│ │ │ type: 'string' │
│ │ │ } │
│ │ │ │
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
│ const T = Type.Number() │ type T = number │ const T = { │
│ │ │ type: 'number' │
│ │ │ } │
│ │ │ │
├────────────────────────────────┼─────────────────────────────┼───────�
没有合适的资源?快使用搜索试试~ 我知道了~
基于树莓派+GPT设计的多功能语音家庭助手.zip(毕设/课设/竞赛/实训/项目开发)
共2000个文件
js:1354个
md:444个
json:151个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 142 浏览量
2024-03-29
10:25:00
上传
评论
收藏 162.8MB ZIP 举报
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于树莓派+GPT设计的多功能语音家庭助手.zip(毕设/课设/竞赛/实训/项目开发) (2000个子文件)
PubSubClient.cpp 23KB
prism-treeview.css 8KB
prism-previewers.css 5KB
prism-coy.css 4KB
prism-twilight.css 4KB
prism-solarizedlight.css 3KB
prism-funky.css 2KB
prism.css 2KB
prism-dark.css 2KB
prism-okaidia.css 2KB
prism-tomorrow.css 2KB
prism-line-highlight.css 2KB
prism-toolbar.css 2KB
prism-inline-color.css 1KB
prism-match-braces.css 815B
prism-line-numbers.css 782B
prism-command-line.css 683B
prism-show-invisibles.css 456B
prism-diff-highlight.css 379B
prism-unescaped-markup.css 359B
prism-wpd.css 235B
prism-autolinker.css 29B
PubSubClient.h 8KB
index.html 11KB
angular.html 690B
regexps.js 197KB
acorn_csp.js 132KB
acorn.js 130KB
js-yaml.js 108KB
index.js 86KB
named_entity_data.js 72KB
index.js 71KB
index.js 63KB
axios.js 62KB
fake-timers-src.js 57KB
prism.js 53KB
yargs-parser.js 46KB
loader.js 43KB
js-yaml.min.js 42KB
acorn_loose.js 41KB
prism-core.js 36KB
merge.js 35KB
index.js 35KB
_stream_readable.js 35KB
argument_parser.js 34KB
prism-sqf.js 33KB
prism-sqf.min.js 33KB
index.js 32KB
sbcs-data-generated.js 31KB
ScriptTransformer.js 29KB
Tokenizer.js 28KB
parse.js 27KB
dumper.js 27KB
response.js 26KB
index.js 25KB
expression.js 24KB
index.js 24KB
components.js 24KB
tokenize.js 22KB
index.js 22KB
args.js 22KB
formatter.js 22KB
_stream_writable.js 21KB
dbcs-codec.js 21KB
resolver_sync.js 20KB
prism-previewers.js 20KB
statement.js 20KB
resolver.js 19KB
watch.js 19KB
axios.min.js 19KB
CoverageReporter.js 18KB
prism-mel.js 17KB
prism-mel.min.js 16KB
index.js 16KB
prism-factor.js 16KB
ascii.js 16KB
typebox.js 16KB
range-tree.js 16KB
expression.js 15KB
legacyFakeTimers.js 15KB
index.js 15KB
action_container.js 15KB
index.js 15KB
simple.js 14KB
application.js 14KB
prism-vim.js 14KB
prism-vim.min.js 14KB
statement.js 14KB
prism-csharp.js 13KB
runTest.js 13KB
TestScheduler.js 13KB
index.js 13KB
identifier.js 13KB
utils.js 12KB
request.js 12KB
inliner.js 12KB
watchman.js 12KB
dependencies.js 12KB
walk.js 12KB
SearchSource.js 11KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
- 基于Java和LCN分布式事务框架的设计源码 - tx-lcn
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功