Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/content/docs/clack/guides/best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/clack/packages/prompts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down