mirror of
https://github.com/zoriya/typebox.git
synced 2026-06-02 11:05:26 +00:00
typebox-v3
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 881 KiB After Width: | Height: | Size: 864 KiB |
@@ -1,4 +1,4 @@
|
||||
TypeBox: JSONSchema Type Builder with Static Type Resolution for TypeScript
|
||||
TypeBox: JSON Schema Type Builder with Static Type Resolution for TypeScript
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.9.7",
|
||||
"version": "0.9.8",
|
||||
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
||||
"author": "sinclairzx81",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -48,7 +48,7 @@ The following shows the general usage.
|
||||
```typescript
|
||||
import { Type, Static } from '@sinclair/typebox'
|
||||
|
||||
// Some type...
|
||||
// some type ...
|
||||
|
||||
type Order = {
|
||||
email: string,
|
||||
@@ -57,17 +57,17 @@ type Order = {
|
||||
option: 'pizza' | 'salad' | 'pie'
|
||||
}
|
||||
|
||||
// ...can be expressed as...
|
||||
// ... can be expressed as ...
|
||||
|
||||
const Order = Type.Object({
|
||||
email: Type.Format('email'),
|
||||
email: Type.String({ format: 'email' }),
|
||||
address: Type.String(),
|
||||
quantity: Type.Number({ minimum: 1, maximum: 99 }),
|
||||
option: Type.Union(
|
||||
option: Type.Union([
|
||||
Type.Literal('pizza'),
|
||||
Type.Literal('salad'),
|
||||
Type.Literal('pie')
|
||||
)
|
||||
])
|
||||
})
|
||||
|
||||
// ... which can be reflected
|
||||
@@ -177,11 +177,6 @@ TypeBox provides many functions generate JSON Schema data types. The following t
|
||||
<td><code>const T = Type.Pattern(/foo/)</code></td>
|
||||
<td><code>type T = string</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Format</td>
|
||||
<td><code>const T = Type.Format('date-time')</code></td>
|
||||
<td><code>type T = string</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Guid</td>
|
||||
<td><code>const T = Type.Guid()</code></td>
|
||||
@@ -271,15 +266,10 @@ TypeBox provides many functions generate JSON Schema data types. The following t
|
||||
<td><code>const T = Type.Pattern(/foo/)</code></td>
|
||||
<td><code>{ type: 'string', pattern: 'foo' }</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Format</td>
|
||||
<td><code>const T = Type.Format('date-time')</code></td>
|
||||
<td><code>{ type: 'string',format: 'date-time' }</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Guid</td>
|
||||
<td><code>const T = Type.Guid()</code></td>
|
||||
<td><code>{ type: 'string', format: '<guid-regex>' }</code></td>
|
||||
<td><code>{ type: 'string', pattern: '<guid-regex>' }</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Type } from '../src/typebox'
|
||||
import { ok, fail } from './validate'
|
||||
|
||||
describe('Format', () => {
|
||||
|
||||
it('date-time', () => {
|
||||
const T = Type.Format('date-time')
|
||||
ok(T, "2018-11-13T20:20:39+00:00")
|
||||
fail(T, "2018-11-13")
|
||||
fail(T, "20:20:39+00:00")
|
||||
fail(T, "string")
|
||||
})
|
||||
|
||||
it('email', () => {
|
||||
const T = Type.Format('email')
|
||||
ok(T, "dave@domain.com")
|
||||
fail(T, "orange")
|
||||
})
|
||||
})
|
||||
@@ -19,7 +19,6 @@ import './tuple'
|
||||
|
||||
// Extended
|
||||
import './pattern'
|
||||
import './format'
|
||||
import './guid'
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Type } from '../src/typebox'
|
||||
import { ok, fail } from './validate'
|
||||
|
||||
describe("String", () => {
|
||||
|
||||
it('String', () => {
|
||||
const T = Type.String()
|
||||
ok(T, 'hello')
|
||||
@@ -11,4 +12,18 @@ describe("String", () => {
|
||||
fail(T, true)
|
||||
fail(T, null)
|
||||
})
|
||||
|
||||
it('DateTime', () => {
|
||||
const T = Type.String({ format: 'date-time' })
|
||||
ok(T, "2018-11-13T20:20:39+00:00")
|
||||
fail(T, "2018-11-13")
|
||||
fail(T, "20:20:39+00:00")
|
||||
fail(T, "string")
|
||||
})
|
||||
|
||||
it('Email', () => {
|
||||
const T = Type.String({ format: 'email' })
|
||||
ok(T, "dave@domain.com")
|
||||
fail(T, "orange")
|
||||
})
|
||||
})
|
||||
|
||||
+1
-6
@@ -1,6 +1,6 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
|
||||
TypeBox: JSONSchema Type Builder with Static Type Resolution for TypeScript
|
||||
TypeBox: JSON Schema Type Builder with Static Type Resolution for TypeScript
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
@@ -559,11 +559,6 @@ export class Type {
|
||||
|
||||
// #region Aliases
|
||||
|
||||
/** Creates a `string` type that validates with the given format. Alias for ```Type.String({ format: '...' })``` */
|
||||
public static Format(format: FormatOption): TString {
|
||||
return this.String({ format })
|
||||
}
|
||||
|
||||
/** Creates a `string` type that validates for the given regular expression. Alias for ```Type.String({ pattern: '...' })``` */
|
||||
public static Pattern(regex: RegExp): TString {
|
||||
return this.String({ pattern: regex.source })
|
||||
|
||||
Reference in New Issue
Block a user