/
QuestionOptions.ts
46 lines (42 loc) 路 1.11 KB
/
QuestionOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { Maybe, Unary } from "@lou.codes/types";
/**
* Options object for the `question` function.
*/
export type QuestionOptions<FormattedValue = string> = {
/**
* Function to format the question's answer given by the user.
*
* @example
* ```typescript
* {
* format: value => parseInt(value, 18),
* }
* ```
* @param input The question's answer given by the user.
* @returns Formatted value.
*/
readonly format?: Unary<string, FormattedValue>;
/**
* Query to show to the user.
*/
readonly query: string;
/**
* Whether to retry the question if the answer is invalid.
*/
readonly retry?: boolean;
/**
* Function to validate the question's answer given by the user (after formatting).
* Returning an string will be used to reject with an error, while an empty
* string or undefined is considered valid.
*
* @example
* ```typescript
* {
* validate: value => value % 2 === 0,
* }
* ```
* @param input The question's answer given by the user.
* @returns Either an error, an empty string or undefined.
*/
readonly validate?: Unary<FormattedValue, Maybe<string>>;
};