diff --git a/website/src/routes/guides/(main-concepts)/pipelines/index.mdx b/website/src/routes/guides/(main-concepts)/pipelines/index.mdx index ab12868b2..5ee46e782 100644 --- a/website/src/routes/guides/(main-concepts)/pipelines/index.mdx +++ b/website/src/routes/guides/(main-concepts)/pipelines/index.mdx @@ -31,28 +31,7 @@ Validation functions examine the input and, if the input does not meet a certain > By default I run a pipeline completely, even if an error is thrown in between, to collect all issues. If you want me to abort the pipeline early after the first error is thrown, you have to set the `abortPipeEarly` option of `parse` or `safeParse` to `true`. Learn more here. -### Example - -For example, a validation function that controls the length of a string might look like the following. - -```ts -import { getOutput, getPipeIssues, string } from 'valibot'; // 0.56 kB - -const StringSchema = string([ - (input) => { - if (input.length > 10) { - return getPipeIssues('custom', 'Invalid length', input); - } - return getOutput(input); - }, -]); -``` - -### Utility functions - -Since the code of a pipeline, as seen in the previous example, can quickly become confusing. I provide you with small utility functions that make your code more understandable and readable. - -Utility functions: `bytes`, `cuid2`, `custom`, `email`, `emoji`, `endsWith`, `excludes`, `finite`, `includes`, `integer`, `ip`, `ipv4`, `ipv6`, `isoDate`, `isoDateTime`, `isoTime`, `isoTimeSecond`, `isoTimestamp`, `isoWeek`, `length`, `maxBytes`, `maxLength`, `maxSize`, `maxValue`, `mimeType`, `minBytes`, `minLength`, `minSize`, `minValue`, `multipleOf`, `notBytes`, `notLength`, `notSize`, `notValue`, `regex`, `safeInteger`, `size`, `startsWith`, `ulid`, `url`, `uuid`, `value` +Validation functions: `bytes`, `cuid2`, `custom`, `email`, `emoji`, `endsWith`, `excludes`, `finite`, `includes`, `integer`, `ip`, `ipv4`, `ipv6`, `isoDate`, `isoDateTime`, `isoTime`, `isoTimeSecond`, `isoTimestamp`, `isoWeek`, `length`, `maxBytes`, `maxLength`, `maxSize`, `maxValue`, `mimeType`, `minBytes`, `minLength`, `minSize`, `minValue`, `multipleOf`, `notBytes`, `notLength`, `notSize`, `notValue`, `regex`, `safeInteger`, `size`, `startsWith`, `ulid`, `url`, `uuid`, `value` Some of these utility functions can be used in the pipeline of different schema functions. For example, `minValue` can be used in the pipeline of `string`, `number`, `bigint` and `date`. @@ -78,27 +57,15 @@ const UsernameSchema = string([ ]); ``` +> You can forward the issues of a pipeline validation to a child. See the methods guide for more information. + ## Transformations Transformation functions allow to change the value of an input, but not the data type. This can be useful for example to remove spaces at the beginning or end of a string or to force a minimum or maximum value. > If you also want to change the data type, you must explicitly use the `transform` method. -### Example - -A transformation function that enforces a minimum value of a number could look like the following. - -```ts -import { getOutput, number } from 'valibot'; // 0.53 kB - -const NumberSchema = number([(input) => getOutput(input > 10 ? input : 10)]); -``` - -### Utility functions - -To make the code of a pipeline more readable, you can use the utility functions I provide for transformations. - -Utility functions: `toCustom`, `toLowerCase`, `toMaxValue`, `toMinValue`, `toTrimmed`, `toTrimmedEnd`, `toTrimmedStart`, `toUpperCase` +Transformation functions: `toCustom`, `toLowerCase`, `toMaxValue`, `toMinValue`, `toTrimmed`, `toTrimmedEnd`, `toTrimmedStart`, `toUpperCase` ```ts import { number, toMinValue } from 'valibot'; // 0.57 kB