Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(api): add and fill boolean schema docs #316

Merged
merged 3 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 108 additions & 1 deletion website/src/routes/api/(schemas)/boolean/index.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,116 @@
---
title: boolean
description: Creates a boolean schema.
contributors:
- wout-junius
- fabian-hiller
---

import { Link } from '@builder.io/qwik-city';
import { ApiList, Property } from '~/components';

# boolean

> 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/boolean/boolean.ts).
Creates a boolean schema.

```ts
// Boolean schema with an optional pipe
const Schema = boolean(pipe);

// Boolean schema with an optional message and pipe
const Schema = boolean(message, pipe);
```

## Parameters

- `message` <Property {...properties.message} />
- `pipe` <Property {...properties.pipe}/>

### Explanation

With `boolean` you can validate the data type of the input and with `pipe` you can transform and validate the further details of the boolean. If the input is not a boolean, you can use `message` to customize the error message.

> Instead of using the `pipe` to force `true` or `false` as a value, in most cases it makes more sense to use <Link href="../literal/">`literal`</Link> for better typing.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `boolean` can be used.

### Custom message

Boolean schema with a custom error message.

```ts
const BooleanSchema = boolean('A boolean is required');
```

## Related

The following APIs can be combined with `boolean`.

### Methods

<ApiList
items={[
'brand',
'coerce',
'fallback',
'getDefault',
'getDefaults',
'getFallback',
'getFallbacks',
'is',
'parse',
'safeParse',
'transform',
]}
/>

### Transformations

<ApiList items={['toCustom', 'toMaxValue', 'toMinValue']} />

### Validations

<ApiList items={['custom', 'maxValue', 'minValue', 'notValue', 'value']} />

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: ['boolean'],
},
'undefined',
],
},
Schema: {
type: [
{
type: 'custom',
name: 'BooleanSchema',
href: '../BooleanSchema/',
},
],
},
};
64 changes: 64 additions & 0 deletions website/src/routes/api/(types)/BooleanSchema/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: BooleanSchema
description: Boolean schema type.
contributors:
- wout-junius
- fabian-hiller
---

import { Property } from '~/components';

# BooleanSchema

Boolean schema type.

## Definition

- `BooleanSchema` <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: [
'boolean',
{
type: 'custom',
name: 'TOutput',
default: 'boolean',
},
],
},
],
},
type: {
type: {
type: 'string',
value: 'boolean',
},
},
message: {
type: {
type: 'custom',
name: 'ErrorMessage',
href: '../ErrorMessage/',
},
},
pipe: {
type: [
{
type: 'custom',
name: 'Pipe',
href: '../Pipe/',
generics: ['boolean'],
},
'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 @@ -196,6 +196,7 @@
- [BaseValidation](/api/BaseValidation/)
- [BigintSchema](/api/BigintSchema/)
- [BlobSchema](/api/BlobSchema/)
- [BooleanSchema](/api/BooleanSchema/)
- [DateSchema](/api/DateSchema/)
- [Enum](/api/Enum/)
- [EnumSchema](/api/EnumSchema/)
Expand Down
Loading