@tusent.io/schema v1.6.1
@tusent.io/schema
Contents
Types
string
Matches any string value.
Example:
{ "type": "string" }number
Matches any number value except positive and negative Infinity. By default, the number is not allowed to be NaN. To allow infinities or NaN values, set the finite option to false or the allowNaN option to true respectively.
allowNaN?: boolean- Whether to allowNaNvalues. Defaults tofalse.finite?: boolean- Whether to disallow positive and negativeInfinityvalues. Defaults totrue.
Example:
{
"type": "number",
"allowNaN": true
}integer
Matches any integer value. By default, the number is not allowed to be NaN. To allow NaN values, set the allowNaN option to true.
allowNaN?: boolean- Whether to allowNaNvalues. Defaults tofalse.
Example:
{ "type": "integer" }boolean
Matches strictly true or false.
Example:
{ "type": "boolean" }null
Matches either null or undefined.
Example:
{ "type": "null" }object
Matches an object with specific properties. By default, all properties are required and the object is not allowed to have any additional properties. To allow additional properties, set the strict option to false.
fields: Record<string, Schema>- An object of schemas to match against the object's properties.[key: string]: Schema- The key is the name of the property and the value is the schema to match against the property..required?: boolean- Whether the property is required. Defaults totrue.
strict?: boolean- Whether to disallow additional properties. Defaults totrue.
Example:
{
"type": "object",
"fields": {
"name": { "type": "string" },
"age": { "type": "number" }
}
}array
Matches an array with items matching a specific schema. By default, its length is not checked. To check its length, either use the length or minLength/maxLength options.
item: Schema- The schema to match against all of the array's items.length?: number- Makes sure the array's length is equal to this specific value.minLength?: number- Makes sure the array's length is greater than or equal to this specific value. This option cannot be used together with thelengthoption.maxLength?: number- Makes sure the array's length is less than or equal to this specific value. This option cannot be used together with thelengthoption.
tuple
Matches an array with a specific length and specific items.
items: Schema[]- An array of schemas to match against the array's items.
Example: The following schema will match an array with two items, the first being a string and the second being a number.
{
"type": "tuple",
"items": [{ "type": "string" }, { "type": "number" }]
}const
Matches a specific value. Supports deep equality checks for objects and arrays.
value: any- The value to match.
Example:
{
"type": "const",
"value": 42
}enum
Matches a specific set of values.
variants: unknown[]- An array of values to match against. Each variant is matched like aconstschema. (Must have at least one item.)
union
Matches any of the given schemas.
variants: Schema[]- An array of schemas to match against. (Must have at least one item.)
Example:
{
"type": "union",
"variants": [{ "type": "string" }, { "type": "number" }]
}any
Matches any value including undefined and null.
Example:
{ "type": "any" }8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago