@topcli/prompts 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ interface PromptValidator<T = string | string[] | boolean> {
2
+ validate: (input: T) => boolean;
3
+ error: (input: T) => string;
4
+ }
5
+ declare function required<T = string | string[] | boolean>(): PromptValidator<T>;
6
+
7
+ declare class PromptAgent<T = string> {
8
+ #private;
9
+ /**
10
+ * The prompts answers queue.
11
+ * When not empty, any prompt will be answered by the first answer in this list.
12
+ */
13
+ nextAnswers: T[];
14
+ static agent<T>(): PromptAgent<T>;
15
+ constructor(instancier: symbol);
16
+ /**
17
+ * Programmatically set the next answer for any prompt (`question()`, `confirm()`, `select()`)
18
+ *
19
+ * This is useful for testing.
20
+ *
21
+ * @example
22
+ * ```js
23
+ * const promptAgent = PromptAgent.agent();
24
+ * promptAgent.nextAnswer("toto");
25
+ *
26
+ * const input = await question("what is your name?");
27
+ * assert.equal(input, "toto");
28
+ * ```
29
+ */
30
+ nextAnswer(value: T): void;
31
+ }
32
+
33
+ interface SharedOptions {
34
+ stdin?: NodeJS.ReadStream & {
35
+ fd: 0;
36
+ };
37
+ stdout?: NodeJS.WriteStream & {
38
+ fd: 1;
39
+ };
40
+ }
41
+ interface Choice<T = any> {
42
+ value: T;
43
+ label: string;
44
+ description?: string;
45
+ }
46
+
47
+ interface QuestionOptions extends SharedOptions {
48
+ defaultValue?: string;
49
+ validators?: PromptValidator[];
50
+ secure?: boolean;
51
+ }
52
+
53
+ interface ConfirmOptions extends SharedOptions {
54
+ initial?: boolean;
55
+ }
56
+
57
+ interface MultiselectOptions extends SharedOptions {
58
+ choices: (Choice | string)[];
59
+ maxVisible?: number;
60
+ preSelectedChoices?: (Choice | string)[];
61
+ validators?: PromptValidator[];
62
+ autocomplete?: boolean;
63
+ caseSensitive?: boolean;
64
+ }
65
+
66
+ interface SelectOptions extends SharedOptions {
67
+ choices: (Choice | string)[];
68
+ maxVisible?: number;
69
+ ignoreValues?: (string | number | boolean)[];
70
+ }
71
+
72
+ declare function question(message: string, options?: QuestionOptions): Promise<string>;
73
+ declare function select(message: string, options: SelectOptions): Promise<string>;
74
+ declare function confirm(message: string, options: ConfirmOptions): Promise<boolean>;
75
+ declare function multiselect(message: string, options: MultiselectOptions): Promise<string[]>;
76
+
77
+ export { type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, type SharedOptions, confirm, multiselect, question, required, select };
@@ -0,0 +1,77 @@
1
+ interface PromptValidator<T = string | string[] | boolean> {
2
+ validate: (input: T) => boolean;
3
+ error: (input: T) => string;
4
+ }
5
+ declare function required<T = string | string[] | boolean>(): PromptValidator<T>;
6
+
7
+ declare class PromptAgent<T = string> {
8
+ #private;
9
+ /**
10
+ * The prompts answers queue.
11
+ * When not empty, any prompt will be answered by the first answer in this list.
12
+ */
13
+ nextAnswers: T[];
14
+ static agent<T>(): PromptAgent<T>;
15
+ constructor(instancier: symbol);
16
+ /**
17
+ * Programmatically set the next answer for any prompt (`question()`, `confirm()`, `select()`)
18
+ *
19
+ * This is useful for testing.
20
+ *
21
+ * @example
22
+ * ```js
23
+ * const promptAgent = PromptAgent.agent();
24
+ * promptAgent.nextAnswer("toto");
25
+ *
26
+ * const input = await question("what is your name?");
27
+ * assert.equal(input, "toto");
28
+ * ```
29
+ */
30
+ nextAnswer(value: T): void;
31
+ }
32
+
33
+ interface SharedOptions {
34
+ stdin?: NodeJS.ReadStream & {
35
+ fd: 0;
36
+ };
37
+ stdout?: NodeJS.WriteStream & {
38
+ fd: 1;
39
+ };
40
+ }
41
+ interface Choice<T = any> {
42
+ value: T;
43
+ label: string;
44
+ description?: string;
45
+ }
46
+
47
+ interface QuestionOptions extends SharedOptions {
48
+ defaultValue?: string;
49
+ validators?: PromptValidator[];
50
+ secure?: boolean;
51
+ }
52
+
53
+ interface ConfirmOptions extends SharedOptions {
54
+ initial?: boolean;
55
+ }
56
+
57
+ interface MultiselectOptions extends SharedOptions {
58
+ choices: (Choice | string)[];
59
+ maxVisible?: number;
60
+ preSelectedChoices?: (Choice | string)[];
61
+ validators?: PromptValidator[];
62
+ autocomplete?: boolean;
63
+ caseSensitive?: boolean;
64
+ }
65
+
66
+ interface SelectOptions extends SharedOptions {
67
+ choices: (Choice | string)[];
68
+ maxVisible?: number;
69
+ ignoreValues?: (string | number | boolean)[];
70
+ }
71
+
72
+ declare function question(message: string, options?: QuestionOptions): Promise<string>;
73
+ declare function select(message: string, options: SelectOptions): Promise<string>;
74
+ declare function confirm(message: string, options: ConfirmOptions): Promise<boolean>;
75
+ declare function multiselect(message: string, options: MultiselectOptions): Promise<string[]>;
76
+
77
+ export { type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, type SharedOptions, confirm, multiselect, question, required, select };