Decompose monolithic readme into docs/ directory structure
This commit is contained in:
39
docs/type-registry.md
Normal file
39
docs/type-registry.md
Normal file
@@ -0,0 +1,39 @@
|
||||
[Overview](./overview.md) | [Installation](./installation.md) | [Usage](./usage.md) | [Types](./types/) | [Values](./values/) | [Syntax](./syntax/) | [TypeRegistry](./type-registry.md) | [TypeCheck](./type-check.md)
|
||||
|
||||
# TypeRegistry
|
||||
|
||||
The TypeBox type system can be extended with additional types and formats using the TypeRegistry and FormatRegistry modules. These modules integrate deeply with TypeBox's internal type checking infrastructure and can be used to create application specific types, or register schematics for alternative specifications.
|
||||
|
||||
## TypeRegistry
|
||||
|
||||
Use the TypeRegistry to register a type. The Kind must match the registered type name.
|
||||
|
||||
```typescript
|
||||
import { TSchema, Kind, TypeRegistry } from "@alkdev/typebox";
|
||||
|
||||
TypeRegistry.Set("Foo", (schema, value) => value === "foo");
|
||||
|
||||
const Foo = { [Kind]: "Foo" } as TSchema;
|
||||
|
||||
const A = Value.Check(Foo, "foo"); // const A = true
|
||||
|
||||
const B = Value.Check(Foo, "bar"); // const B = false
|
||||
```
|
||||
|
||||
## FormatRegistry
|
||||
|
||||
Use the FormatRegistry to register a string format.
|
||||
|
||||
```typescript
|
||||
import { FormatRegistry } from "@alkdev/typebox";
|
||||
|
||||
FormatRegistry.Set("foo", (value) => value === "foo");
|
||||
|
||||
const T = Type.String({ format: "foo" });
|
||||
|
||||
const A = Value.Check(T, "foo"); // const A = true
|
||||
|
||||
const B = Value.Check(T, "bar"); // const B = false
|
||||
```
|
||||
|
||||
Back to [Home](../readme.md)
|
||||
Reference in New Issue
Block a user