Skip to content

Commit

Permalink
Update API reference of methods on website
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed May 25, 2024
1 parent dda719c commit 51ce74d
Show file tree
Hide file tree
Showing 30 changed files with 1,275 additions and 377 deletions.
10 changes: 5 additions & 5 deletions library/src/methods/keyof/keyof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import type {
* Schema type.
*/
type Schema =
| LooseObjectSchema<ObjectEntries, ErrorMessage<LooseObjectIssue> | undefined>
| LooseObjectSchemaAsync<
ObjectEntriesAsync,
ErrorMessage<LooseObjectIssue> | undefined
>
| ObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined>
| ObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<ObjectIssue> | undefined>
| ObjectWithRestSchema<
Expand All @@ -47,11 +52,6 @@ type Schema =
| StrictObjectSchemaAsync<
ObjectEntriesAsync,
ErrorMessage<StrictObjectIssue> | undefined
>
| LooseObjectSchema<ObjectEntries, ErrorMessage<LooseObjectIssue> | undefined>
| LooseObjectSchemaAsync<
ObjectEntriesAsync,
ErrorMessage<LooseObjectIssue> | undefined
>;

/**
Expand Down
1 change: 0 additions & 1 deletion website/src/routes/api/(actions)/brand/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ The following APIs can be combined with `brand`.
'getFallbacks',
'is',
'keyof',
'merge',
'omit',
'parse',
'partial',
Expand Down
1 change: 0 additions & 1 deletion website/src/routes/api/(actions)/transform/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ The following APIs can be combined with `transform`.
'getFallbacks',
'is',
'keyof',
'merge',
'omit',
'parse',
'partial',
Expand Down
98 changes: 88 additions & 10 deletions website/src/routes/api/(methods)/fallback/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: fallback
description: Returns a fallback output value when validating the passed schema failed.
description: >-
Returns a fallback value as output if the input does not match the schema.
source: /methods/fallback/fallback.ts
contributors:
- fabian-hiller
Expand All @@ -14,7 +15,7 @@ import { properties } from './properties';

# fallback

Returns a fallback output value when validating the passed schema failed.
Returns a fallback value as output if the input does not match the schema.

```ts
const Schema = fallback<TSchema, TFallback>(schema, fallback);
Expand All @@ -36,7 +37,7 @@ const Schema = fallback<TSchema, TFallback>(schema, fallback);

> If you only want to set a default value for `null` or `undefined` inputs, you should use <Link href="../optional/">`optional`</Link>, <Link href="../nullable/">`nullable`</Link> or <Link href="../nullish/">`nullish`</Link> instead.
> Warning: The fallback value is not validated. Make sure that the fallback value matches your schema.
> The fallback value is not validated. Make sure that the fallback value matches your schema.
## Returns

Expand All @@ -51,7 +52,7 @@ The following examples show how `fallback` can be used.
Schema that will always return a string output.

```ts
const FallbackStringSchema = fallback(string(), "I'm the fallback!");
const FallbackStringSchema = v.fallback(v.string(), "I'm the fallback!");
```

### Fallback date schema
Expand All @@ -61,7 +62,7 @@ Schema that will always return a [`Date`](https://developer.mozilla.org/en-US/do
> By using a function as the `fallback` parameter, the schema will return a new [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance each time the input does not match the schema.
```ts
const FallbackDateSchema = fallback(date(), () => new Date());
const FallbackDateSchema = v.fallback(v.date(), () => new Date());
```

## Related
Expand All @@ -77,12 +78,15 @@ The following APIs can be combined with `fallback`.
'bigint',
'blob',
'boolean',
'custom',
'date',
'enum_',
'instance',
'intersect',
'lazy',
'literal',
'looseObject',
'looseTuple',
'map',
'nan',
'never',
Expand All @@ -94,14 +98,17 @@ The following APIs can be combined with `fallback`.
'nullish',
'number',
'object',
'objectWithRest',
'optional',
'picklist',
'record',
'set',
'special',
'strictObject',
'strictTuple',
'string',
'symbol',
'tuple',
'tupleWithRest',
'undefined_',
'union',
'unknown',
Expand All @@ -114,22 +121,93 @@ The following APIs can be combined with `fallback`.

<ApiList
items={[
'brand',
'coerce',
'getDefault',
'getDefaults',
'getFallback',
'getFallbacks',
'is',
'keyof',
'merge',
'omit',
'parse',
'partial',
'pick',
'pipe',
'required',
'safeParse',
'transform',
'unwrap',
]}
/>

### Actions

<ApiList
items={[
'bic',
'brand',
'bytes',
'check',
'creditCard',
'cuid2',
'decimal',
'email',
'emoji',
'empty',
'endsWith',
'every',
'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',
'nonEmpty',
'notBytes',
'notLength',
'notSize',
'notValue',
'octal',
'readonly',
'regex',
'safeInteger',
'size',
'some',
'startsWith',
'toLowerCase',
'toMaxValue',
'toMinValue',
'toUpperCase',
'transform',
'trim',
'trimEnd',
'trimStart',
'ulid',
'url',
'uuid',
'value',
]}
/>
6 changes: 6 additions & 0 deletions website/src/routes/api/(methods)/fallback/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export const properties: Record<string, PropertyProps> = {
type: 'custom',
name: 'Fallback',
href: '../Fallback/',
generics: [
{
type: 'custom',
name: 'TSchema',
},
],
},
},
schema: {
Expand Down
4 changes: 2 additions & 2 deletions website/src/routes/api/(methods)/flatten/index.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: flatten
source: /error/flatten/flatten.ts
source: /methods/flatten/flatten.ts
contributors:
- fabian-hiller
---

# flatten

> 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/error/flatten/flatten.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference.
> 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/methods/flatten/flatten.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference.
56 changes: 31 additions & 25 deletions website/src/routes/api/(methods)/forward/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ import { properties } from './properties';
Forwards the issues of the passed validation action.

```ts
const Validation = forward<TInput>(validation, pathList);
const Action = forward<TInput, TIssue>(action, pathList);
```

## Generics

- `TInput` <Property {...properties.TInput} />
- `TIssue` <Property {...properties.TIssue} />

## Parameters

- `validation` <Property {...properties.validation} />
- `action` <Property {...properties.action} />
- `pathList` <Property {...properties.pathList} />

### Explanation

`forward` allows you to forward the issues of the passed `validation` action via a `pathList` to a nested field of a schema.
`forward` allows you to forward the issues of the passed validation `action` via a `pathList` to a nested field of a schema.

## Returns

- `Validation` <Property {...properties.Validation} />
- `Action` <Property {...properties.Action} />

## Examples

Expand All @@ -43,23 +44,22 @@ The following examples show how `forward` can be used.
Schema that ensures that the two passwords match.

```ts
const PasswordSchema = object(
{
password1: string([
minLength(1, 'Please enter your password.'),
minLength(8, 'Your password must have 8 characters or more.'),
]),
password2: string(),
},
[
forward(
custom(
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
const PasswordSchema = v.pipe(
v.object({
password1: v.pipe(
v.string(),
v.minLength(1, 'Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
]
password2: v.string(),
}),
v.forward(
v.check(
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
)
);
```

Expand All @@ -73,10 +73,16 @@ The following APIs can be combined with `forward`.
items={[
'any',
'array',
'custom',
'looseObject',
'looseTuple',
'object',
'objectWithRest',
'record',
'special',
'strictObject',
'strictTuple',
'tuple',
'tupleWithRest',
'union',
'unknown',
'variant',
Expand All @@ -85,21 +91,21 @@ The following APIs can be combined with `forward`.

### Methods

<ApiList
items={['merge', 'omit', 'partial', 'pick', 'required', 'transform']}
/>
<ApiList items={['omit', 'partial', 'pick', 'required']} />

### Validations
### Actions

<ApiList
items={[
'check',
'empty',
'every',
'excludes',
'includes',
'length',
'maxLength',
'minLength',
'nonEmpty',
'notLength',
'some',
]}
Expand Down
Loading

0 comments on commit 51ce74d

Please sign in to comment.