diff --git a/library/src/actions/url/url.ts b/library/src/actions/url/url.ts index a91ea60fc..3d60bebb1 100644 --- a/library/src/actions/url/url.ts +++ b/library/src/actions/url/url.ts @@ -62,24 +62,24 @@ export interface UrlAction< } /** - * Creates a [URL](https://en.wikipedia.org/wiki/URL) validation action. + * Creates an [URL](https://en.wikipedia.org/wiki/URL) validation action. * * Hint: The value is passed to the URL constructor to check if it is valid. * This check is not perfect. For example, values like "abc:1234" are accepted. * - * @returns A URL action. + * @returns An URL action. */ export function url(): UrlAction; /** - * Creates a [URL](https://en.wikipedia.org/wiki/URL) validation action. + * Creates an [URL](https://en.wikipedia.org/wiki/URL) validation action. * * Hint: The value is passed to the URL constructor to check if it is valid. * This check is not perfect. For example, values like "abc:1234" are accepted. * * @param message The error message. * - * @returns A URL action. + * @returns An URL action. */ export function url< TInput extends string, diff --git a/website/src/routes/api/(actions)/maxLength/index.mdx b/website/src/routes/api/(actions)/maxLength/index.mdx index ce68a2fa2..ef776a28f 100644 --- a/website/src/routes/api/(actions)/maxLength/index.mdx +++ b/website/src/routes/api/(actions)/maxLength/index.mdx @@ -1,10 +1,81 @@ --- title: maxLength +description: Creates a max length validation action. source: /actions/maxLength/maxLength.ts contributors: - fabian-hiller + - depsimon --- +import { ApiList, Property } from '~/components'; +import { properties } from './properties'; + # maxLength -> 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/actions/maxLength/maxLength.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference. +Creates a max length validation action. + +```ts +const Action = v.maxLength( + requirement, + message +); +``` + +## Generics + +- `TInput` +- `TRequirement` +- `TMessage` + +## Parameters + +- `requirement` +- `message` + +### Explanation + +With `maxLength` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message. + +## Returns + +- `Action` + +## Examples + +The following examples show how `maxLength` can be used. + +### Maximum string length + +Schema to validate a string with a maximum length of 32 characters. + +```ts +const MaxStringSchema = v.pipe( + v.string(), + v.maxLength(32, 'The string must not exceed 32 characters.') +); +``` + +### Maximum array length + +Schema to validate an array with a maximum length of 5 items. + +```ts +const MaxArraySchema = v.pipe( + v.array(v.number()), + v.maxLength(5, 'The array must not exceed 5 numbers.') +); +``` + +## Related + +The following APIs can be combined with `maxLength`. + +### Schemas + + + +### Methods + + diff --git a/website/src/routes/api/(actions)/maxLength/properties.ts b/website/src/routes/api/(actions)/maxLength/properties.ts new file mode 100644 index 000000000..d94d2e9c9 --- /dev/null +++ b/website/src/routes/api/(actions)/maxLength/properties.ts @@ -0,0 +1,80 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: { + type: 'custom', + name: 'LengthInput', + href: '../LengthInput/', + }, + }, + TRequirement: { + modifier: 'extends', + type: 'number', + }, + TMessage: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'MaxLengthIssue', + href: '../MaxLengthIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + requirement: { + type: { + type: 'custom', + name: 'TRequirement', + }, + }, + message: { + type: { + type: 'custom', + name: 'TMessage', + }, + }, + Action: { + type: { + type: 'custom', + name: 'MaxLengthAction', + href: '../MaxLengthAction/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + { + type: 'custom', + name: 'TMessage', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(actions)/minLength/index.mdx b/website/src/routes/api/(actions)/minLength/index.mdx index c0bf61817..106ee466f 100644 --- a/website/src/routes/api/(actions)/minLength/index.mdx +++ b/website/src/routes/api/(actions)/minLength/index.mdx @@ -1,10 +1,81 @@ --- title: minLength +description: Creates a min length validation action. source: /actions/minLength/minLength.ts contributors: - fabian-hiller + - depsimon --- +import { ApiList, Property } from '~/components'; +import { properties } from './properties'; + # minLength -> 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/actions/minLength/minLength.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference. +Creates a min length validation action. + +```ts +const Action = v.minLength( + requirement, + message +); +``` + +## Generics + +- `TInput` +- `TRequirement` +- `TMessage` + +## Parameters + +- `requirement` +- `message` + +### Explanation + +With `minLength` you can validate the length of a string or array. If the input does not match the `requirement`, you can use `message` to customize the error message. + +## Returns + +- `Action` + +## Examples + +The following examples show how `minLength` can be used. + +### Minumum string length + +Schema to validate a string with a minimum length of 3 characters. + +```ts +const MinStringSchema = v.pipe( + v.string(), + v.minLength(3, 'The string must be 3 or more characters long.') +); +``` + +### Minimum array length + +Schema to validate an array with a minimum length of 5 items. + +```ts +const MinArraySchema = v.pipe( + v.array(v.number()), + v.minLength(5, 'The array must contain 3 numbers or more.') +); +``` + +## Related + +The following APIs can be combined with `minLength`. + +### Schemas + + + +### Methods + + diff --git a/website/src/routes/api/(actions)/minLength/properties.ts b/website/src/routes/api/(actions)/minLength/properties.ts new file mode 100644 index 000000000..fa8ad8c7f --- /dev/null +++ b/website/src/routes/api/(actions)/minLength/properties.ts @@ -0,0 +1,80 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: { + type: 'custom', + name: 'LengthInput', + href: '../LengthInput/', + }, + }, + TRequirement: { + modifier: 'extends', + type: 'number', + }, + TMessage: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'MinLengthIssue', + href: '../MinLengthIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + requirement: { + type: { + type: 'custom', + name: 'TRequirement', + }, + }, + message: { + type: { + type: 'custom', + name: 'TMessage', + }, + }, + Action: { + type: { + type: 'custom', + name: 'MinLengthAction', + href: '../MinLengthAction/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TRequirement', + }, + { + type: 'custom', + name: 'TMessage', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(actions)/url/index.mdx b/website/src/routes/api/(actions)/url/index.mdx index ee33a6f30..0af4f38b0 100644 --- a/website/src/routes/api/(actions)/url/index.mdx +++ b/website/src/routes/api/(actions)/url/index.mdx @@ -1,10 +1,65 @@ --- title: url +description: Creates an URL validation action. source: /actions/url/url.ts contributors: - fabian-hiller + - depsimon --- +import { ApiList, Property } from '~/components'; +import { properties } from './properties'; + # url -> 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/actions/url/url.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 [URL](https://en.wikipedia.org/wiki/URL) validation action. + +```ts +const Action = v.url(message); +``` + +## Generics + +- `TInput` +- `TMessage` + +## Parameters + +- `message` + +### Explanation + +With `url` you can validate the formatting of a string. If the input is not an URL, you can use `message` to customize the error message. + +## Returns + +- `Action` + +## Examples + +The following examples show how `url` can be used. + +### URL schema + +Schema to validate an URL. + +```ts +const UrlSchema = v.pipe( + v.string(), + v.nonEmpty('Please enter your url.'), + v.url('The url is badly formatted.'), + v.endsWith('.com', 'Only ".com" domains are allowed.') +); +``` + +## Related + +The following APIs can be combined with `url`. + +### Schemas + + + +### Methods + + diff --git a/website/src/routes/api/(actions)/url/properties.ts b/website/src/routes/api/(actions)/url/properties.ts new file mode 100644 index 000000000..7717eb8f4 --- /dev/null +++ b/website/src/routes/api/(actions)/url/properties.ts @@ -0,0 +1,58 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'string', + }, + TMessage: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'UrlIssue', + href: '../UrlIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + message: { + type: { + type: 'custom', + name: 'TMessage', + }, + }, + Action: { + type: { + type: 'custom', + name: 'UrlAction', + href: '../UrlAction/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TMessage', + }, + ], + }, + }, +};