<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
┌────────────────────────────────┬─────────
没有合适的资源?快使用搜索试试~ 我知道了~
nest框架的token登录,以及token校验
共2000个文件
js:969个
md:901个
json:124个
0 下载量 165 浏览量
2023-12-14
18:00:07
上传
评论
收藏 38.24MB ZIP 举报
温馨提示
nest框架的token登录,以及token校验
资源推荐
资源详情
资源评论
收起资源包目录
nest框架的token登录,以及token校验 (2000个子文件)
source-map.debug.js 266KB
convert.js 129KB
js-yaml.js 112KB
source-map.js 104KB
typebox.js 97KB
volume.js 90KB
index.js 77KB
dom.js 65KB
fake-timers-src.js 57KB
browser-source-map-support.js 52KB
BigInteger.js 51KB
loader.js 46KB
yargs-parser.js 46KB
index.js 45KB
index.js 45KB
index.es.js 44KB
semver.js 43KB
index.js 42KB
sbcs.js 40KB
source-map-consumer.js 40KB
js-yaml.min.js 39KB
strict-boolean-expressions.js 37KB
consistent-type-imports.js 36KB
index.js 35KB
errors.js 34KB
node-internal-modules-esm-resolve.js 32KB
BigInteger.min.js 31KB
dumper.js 31KB
_stream_readable.js 31KB
config-set.js 30KB
index.js 29KB
visitor.js 28KB
response.js 27KB
node-utils.js 27KB
parse.js 27KB
member-ordering.js 27KB
source-map.min.js 26KB
compiler.js 26KB
estraverse.js 26KB
webworker.js 26KB
bin.js 26KB
no-unnecessary-condition.js 25KB
prefer-string-starts-ends-with.js 24KB
padding-line-between-statements.js 24KB
collectUnusedVariables.js 23KB
ts-compiler.js 23KB
naming-convention.js 23KB
no-misused-promises.js 22KB
Referencer.js 22KB
no-unused-vars.js 22KB
ts-jest-transformer.js 21KB
repl.js 21KB
no-shadow.js 21KB
resolver_sync.js 20KB
DirectoryWatcher.js 20KB
_stream_writable.js 20KB
resolver.js 20KB
analyzeChain.js 19KB
index.js 19KB
glob.js 19KB
glob.js 19KB
check.js 19KB
getOperatorPrecedence.js 19KB
node-internal-modules-cjs-loader.js 19KB
cast.js 18KB
source-map-support.js 18KB
getWatchProgramsForProjects.js 18KB
indent.js 18KB
unified-signatures.js 17KB
create.js 17KB
migrate.js 17KB
node.js 17KB
index.js 17KB
mbcs.js 17KB
index.js 17KB
explicit-module-boundary-types.js 16KB
no-redundant-type-constituents.js 16KB
convert.js 16KB
prefer-nullish-coalescing.js 16KB
compareNodes.js 15KB
index.js 15KB
key-spacing.js 14KB
no-floating-promises.js 14KB
no-confusing-void-expression.js 14KB
ScopeBase.js 14KB
application.js 14KB
lines-around-comment.js 14KB
source-map-generator.js 14KB
file-coverage.js 14KB
configuration.js 14KB
source-node.js 13KB
no-unsafe-assignment.js 13KB
ts-internals.js 13KB
ClassVisitor.js 13KB
validator.js 13KB
runTest.js 13KB
util.js 13KB
gatherLogicalOperands.js 13KB
errors.js 12KB
request.js 12KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
流连勿忘返
- 粉丝: 4405
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功