-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2d7b7d
commit 7eb1c4f
Showing
3 changed files
with
184 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,117 @@ | ||
--- | ||
title: blob | ||
description: Creates a blob schema. | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { ApiList, Property } from '~/components'; | ||
|
||
# blob | ||
|
||
> The content of this page is not yet ready. Until then just use the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/schemas/blob/blob.ts). | ||
Creates a blob schema. | ||
|
||
```ts | ||
// Blob schema with an optional pipe | ||
const Schema = blob(pipe); | ||
|
||
// Blob schema with an optional message and pipe | ||
const Schema = blob(message, pipe); | ||
``` | ||
|
||
## Parameters | ||
|
||
- `message` <Property {...properties.message} /> | ||
- `pipe` <Property {...properties.pipe}/> | ||
|
||
### Explanation | ||
|
||
With `blob` you can validate the data type of the input and with `pipe` you can transform and validate the further details of the blob. If the input is not a blob, you can use `message` to customize the error message. | ||
|
||
## Returns | ||
|
||
- `Schema` <Property {...properties.Schema} /> | ||
|
||
## Examples | ||
|
||
The following examples show how `blob` can be used. | ||
|
||
### Image schema | ||
|
||
Schema to validate an image. | ||
|
||
```ts | ||
const ImageSchema = blob('Please select an image file.', [ | ||
mimeType(['image/jpeg', 'image/png'], 'Please select a JPEG or PNG file.'), | ||
maxSize(1024 * 1024 * 10, 'Please select a file smaller than 10 MB.'), | ||
]); | ||
``` | ||
|
||
## Related | ||
|
||
The following APIs can be combined with `blob`. | ||
|
||
### Methods | ||
|
||
<ApiList | ||
items={[ | ||
'brand', | ||
'coerce', | ||
'fallback', | ||
'getDefault', | ||
'getDefaults', | ||
'getFallback', | ||
'getFallbacks', | ||
'is', | ||
'parse', | ||
'safeParse', | ||
'transform', | ||
]} | ||
/> | ||
|
||
### Transformations | ||
|
||
<ApiList items={['toCustom']} /> | ||
|
||
### Validations | ||
|
||
<ApiList | ||
items={['custom', 'maxSize', 'mimeType', 'minSize', 'notSize', 'size']} | ||
/> | ||
|
||
export const properties = { | ||
message: { | ||
type: [ | ||
{ | ||
type: 'custom', | ||
name: 'ErrorMessage', | ||
href: '../ErrorMessage/', | ||
}, | ||
'undefined', | ||
], | ||
default: { | ||
type: 'string', | ||
value: 'Invalid type', | ||
}, | ||
}, | ||
pipe: { | ||
type: [ | ||
{ | ||
type: 'custom', | ||
name: 'Pipe', | ||
href: '../Pipe/', | ||
generics: [{ type: 'custom', name: 'Blob' }], | ||
}, | ||
'undefined', | ||
], | ||
}, | ||
Schema: { | ||
type: [ | ||
{ | ||
type: 'custom', | ||
name: 'BlobSchema', | ||
href: '../BlobSchema/', | ||
}, | ||
], | ||
}, | ||
}; |
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,74 @@ | ||
--- | ||
title: BlobSchema | ||
description: Blob schema type. | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { Property } from '~/components'; | ||
|
||
# BlobSchema | ||
|
||
Blob schema type. | ||
|
||
## Definition | ||
|
||
- `BlobSchema` <Property {...properties.BaseSchema} /> | ||
- `type` <Property {...properties.type} /> | ||
- `message` <Property {...properties.message} /> | ||
- `pipe` <Property {...properties.pipe} /> | ||
|
||
export const properties = { | ||
BaseSchema: { | ||
type: [ | ||
{ | ||
type: 'custom', | ||
name: 'BaseSchema', | ||
href: '../BaseSchema/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'Blob', | ||
}, | ||
{ | ||
type: 'custom', | ||
name: 'TOutput', | ||
default: { | ||
type: 'custom', | ||
name: 'Blob', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
type: { | ||
type: { | ||
type: 'string', | ||
value: 'blob', | ||
}, | ||
}, | ||
message: { | ||
type: { | ||
type: 'custom', | ||
name: 'ErrorMessage', | ||
href: '../ErrorMessage/', | ||
}, | ||
}, | ||
pipe: { | ||
type: [ | ||
{ | ||
type: 'custom', | ||
name: 'Pipe', | ||
href: '../Pipe/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'Blob', | ||
}, | ||
], | ||
}, | ||
'undefined', | ||
], | ||
}, | ||
}; |
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