-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content to intersect API reference on website
- Loading branch information
1 parent
c011cd6
commit c0831b0
Showing
14 changed files
with
472 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,197 @@ | ||
--- | ||
title: intersect | ||
description: Creates an intersect schema. | ||
source: /schemas/intersect/intersect.ts | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { Link } from '@builder.io/qwik-city'; | ||
import { ApiList, Property } from '~/components'; | ||
import { properties } from './properties'; | ||
|
||
# intersect | ||
|
||
> The content of this page is not yet ready. Until then, please use the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/intersect/intersect.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference. | ||
Creates an intersect schema. | ||
|
||
> I recommend that you read the <Link href="/guides/intersections">intersections guide</Link> before using this schema function. | ||
```ts | ||
// Intersect schema with an optional pipe | ||
const Schema = intersect<TOptions>(options, pipe); | ||
|
||
// Intersect schema with an optional message and pipe | ||
const Schema = intersect<TOptions>(options, message, pipe); | ||
``` | ||
|
||
## Generics | ||
|
||
- `TOptions` <Property {...properties.TOptions} /> | ||
|
||
## Parameters | ||
|
||
- `options` <Property {...properties.options} /> | ||
- `message` <Property {...properties.message} /> | ||
- `pipe` <Property {...properties.pipe} /> | ||
|
||
### Explanation | ||
|
||
With `intersect` you can validate if the input matches each of the given `options`. With `pipe` you can transform and validate the further details of the intersection. If the output of the intersection cannot be successfully merged, you can use `message` to customize the error message. | ||
|
||
## Returns | ||
|
||
- `Schema` <Property {...properties.Schema} /> | ||
|
||
## Examples | ||
|
||
The following examples show how `intersect` can be used. | ||
|
||
### Object intersection | ||
|
||
Schema that combines two object schemas. | ||
|
||
```ts | ||
const ObjectSchema = intersect([ | ||
object({ foo: string() }), | ||
object({ bar: number() }), | ||
]); | ||
``` | ||
|
||
## Related | ||
|
||
The following APIs can be combined with `intersect`. | ||
|
||
### Schemas | ||
|
||
<ApiList | ||
items={[ | ||
'any', | ||
'array', | ||
'bigint', | ||
'blob', | ||
'boolean', | ||
'date', | ||
'enum_', | ||
'instance', | ||
'literal', | ||
'map', | ||
'nan', | ||
'never', | ||
'nonNullable', | ||
'nonNullish', | ||
'nonOptional', | ||
'null_', | ||
'nullable', | ||
'nullish', | ||
'number', | ||
'object', | ||
'optional', | ||
'picklist', | ||
'record', | ||
'recursive', | ||
'set', | ||
'special', | ||
'string', | ||
'symbol', | ||
'tuple', | ||
'undefined_', | ||
'union', | ||
'intersect', | ||
'unknown', | ||
'variant', | ||
'void_', | ||
]} | ||
/> | ||
|
||
### Methods | ||
|
||
<ApiList | ||
items={[ | ||
'brand', | ||
'coerce', | ||
'fallback', | ||
'getDefault', | ||
'getDefaults', | ||
'getFallback', | ||
'getFallbacks', | ||
'is', | ||
'parse', | ||
'safeParse', | ||
'transform', | ||
]} | ||
/> | ||
|
||
### Transformations | ||
|
||
<ApiList | ||
items={[ | ||
'toCustom', | ||
'toLowerCase', | ||
'toMaxValue', | ||
'toMinValue', | ||
'toTrimmed', | ||
'toTrimmedEnd', | ||
'toTrimmedStart', | ||
'toUpperCase', | ||
]} | ||
/> | ||
|
||
### Validations | ||
|
||
<ApiList | ||
items={[ | ||
'bic', | ||
'bytes', | ||
'creditCard', | ||
'cuid2', | ||
'custom', | ||
'decimal', | ||
'email', | ||
'emoji', | ||
'endsWith', | ||
'excludes', | ||
'finite', | ||
'hash', | ||
'hexadecimal', | ||
'hexColor', | ||
'imei', | ||
'includes', | ||
'integer', | ||
'ip', | ||
'ipv4', | ||
'ipv6', | ||
'isoDate', | ||
'isoDateTime', | ||
'isoTime', | ||
'isoTimeSecond', | ||
'isoTimestamp', | ||
'isoWeek', | ||
'length', | ||
'mac', | ||
'mac48', | ||
'mac64', | ||
'maxBytes', | ||
'maxLength', | ||
'maxSize', | ||
'maxValue', | ||
'mimeType', | ||
'minBytes', | ||
'minLength', | ||
'minSize', | ||
'minValue', | ||
'multipleOf', | ||
'notBytes', | ||
'notLength', | ||
'notSize', | ||
'notValue', | ||
'octal', | ||
'regex', | ||
'safeInteger', | ||
'size', | ||
'startsWith', | ||
'ulid', | ||
'url', | ||
'uuid', | ||
'value', | ||
]} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { PropertyProps } from '~/components'; | ||
|
||
export const properties: Record<string, PropertyProps> = { | ||
TOptions: { | ||
type: { | ||
type: 'custom', | ||
name: 'IntersectOptions', | ||
href: '../IntersectOptions/', | ||
}, | ||
}, | ||
options: { | ||
type: { | ||
type: 'custom', | ||
name: 'TOptions', | ||
}, | ||
}, | ||
message: { | ||
type: { | ||
type: 'union', | ||
options: [ | ||
{ | ||
type: 'custom', | ||
name: 'ErrorMessage', | ||
href: '../ErrorMessage/', | ||
}, | ||
'undefined', | ||
], | ||
}, | ||
default: { | ||
type: 'string', | ||
value: 'Invalid type', | ||
}, | ||
}, | ||
pipe: { | ||
type: { | ||
type: 'union', | ||
options: [ | ||
{ | ||
type: 'custom', | ||
name: 'Pipe', | ||
href: '../Pipe/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'IntersectOutput', | ||
href: '../IntersectOutput/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'TOptions', | ||
href: '../TOptions/', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
'undefined', | ||
], | ||
}, | ||
}, | ||
Schema: { | ||
type: { | ||
type: 'custom', | ||
name: 'IntersectSchema', | ||
href: '../IntersectSchema/', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: IntersectInput | ||
description: Intersect input inference type. | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
# IntersectInput | ||
|
||
Intersect input inference type. | ||
|
||
```ts | ||
// Create object schemas | ||
const ObjectSchemas = [ | ||
object({ key1: transform(string(), (input) => input.length) }), | ||
object({ key2: transform(string(), (input) => input.length) }), | ||
]; | ||
|
||
// Infer object intersect input type | ||
type ObjectInput = IntersectInput<typeof ObjectSchemas>; // { key1: string } & { key2: string } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: IntersectOptions | ||
description: Intersect options type. | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { Property } from '~/components'; | ||
import { properties } from './properties'; | ||
|
||
# IntersectOptions | ||
|
||
Intersect options type. | ||
|
||
## Definition | ||
|
||
- `IntersectOptions` <Property {...properties.IntersectOptions} /> |
37 changes: 37 additions & 0 deletions
37
website/src/routes/api/(types)/IntersectOptions/properties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { PropertyProps } from '~/components'; | ||
|
||
export const properties: Record<string, PropertyProps> = { | ||
IntersectOptions: { | ||
type: { | ||
type: 'custom', | ||
name: 'MaybeReadonly', | ||
href: '../MaybeReadonly/', | ||
generics: [ | ||
{ | ||
type: 'tuple', | ||
items: [ | ||
{ | ||
type: 'custom', | ||
name: 'BaseSchema', | ||
href: '../BaseSchema/', | ||
}, | ||
{ | ||
type: 'custom', | ||
name: 'BaseSchema', | ||
href: '../BaseSchema/', | ||
}, | ||
{ | ||
type: 'array', | ||
spread: true, | ||
item: { | ||
type: 'custom', | ||
name: 'BaseSchema', | ||
href: '../BaseSchema/', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.