diff --git a/src/content/docs/clack/guides/best-practices.mdx b/src/content/docs/clack/guides/best-practices.mdx index 878edcb..90a4747 100644 --- a/src/content/docs/clack/guides/best-practices.mdx +++ b/src/content/docs/clack/guides/best-practices.mdx @@ -53,6 +53,18 @@ const age = await text({ }); ``` +A [Standard Schema](https://github.com/standard-schema/standard-schema) can be used, for example using [Arktype](https://arktype.io/): + +```ts twoslash +import { text } from '@clack/prompts'; +import { type } from 'arktype'; + +const name = await text({ + message: 'Enter your name (letters only)', + validate: type('string.alpha').describe('Name can only contain letters'), +}); +``` + ### 3. Consistent Messaging Use clear and consistent messaging across your prompts: diff --git a/src/content/docs/clack/packages/prompts.mdx b/src/content/docs/clack/packages/prompts.mdx index eaeb03b..7b76415 100644 --- a/src/content/docs/clack/packages/prompts.mdx +++ b/src/content/docs/clack/packages/prompts.mdx @@ -130,7 +130,7 @@ Options: - `placeholder`: A visual hint shown when the field has no content. - `defaultValue`: A fallback value returned when the user provides nothing (empty input). - `initialValue`: The starting value shown when the prompt first renders. Users can edit this value before submitting. -- `validate`: A function that validates user input. Return a `string` or `Error` to show as a validation error, or `undefined` to accept the result. +- `validate`: A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) that validates user input. Return a `string` or `Error` to show as a validation error, or `undefined` to accept the result. - All [Common Options](#common-options) ### Password Input @@ -163,7 +163,7 @@ Options: - `message`: The prompt message or question shown to the user above the input. - `mask`: Character to use for masking input. Default: `'▪/•'`. -- `validate`: A function that validates user input. Return a `string` or `Error` to show as a validation error, or `undefined` to accept the result. +- `validate`: A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) that validates user input. Return a `string` or `Error` to show as a validation error, or `undefined` to accept the result. - `clearOnError`: When enabled it causes the input to be cleared if/when validation fails. Default: `false`. - All [Common Options](#common-options)