Skip to content

Commit

Permalink
Add blob API reference to website
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Dec 11, 2023
1 parent b2d7b7d commit 7eb1c4f
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 1 deletion.
110 changes: 109 additions & 1 deletion website/src/routes/api/(schemas)/blob/index.mdx
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/',
},
],
},
};
74 changes: 74 additions & 0 deletions website/src/routes/api/(types)/BlobSchema/index.mdx
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',
],
},
};
1 change: 1 addition & 0 deletions website/src/routes/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
- [BaseTransformation](/api/BaseTransformation/)
- [BaseValidation](/api/BaseValidation/)
- [BigintSchema](/api/BigintSchema/)
- [BlobSchema](/api/BlobSchema/)
- [ErrorMessage](/api/ErrorMessage/)
- [Input](/api/Input/)
- [InvalidActionResult](/api/InvalidActionResult/)
Expand Down

0 comments on commit 7eb1c4f

Please sign in to comment.