1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export = prompts;
|
15 |
|
16 | import { Readable, Writable } from 'stream';
|
17 |
|
18 | declare function prompts<T extends string = string>(
|
19 | questions: prompts.PromptObject<T> | Array<prompts.PromptObject<T>>,
|
20 | options?: prompts.Options
|
21 | ): Promise<prompts.Answers<T>>;
|
22 |
|
23 | declare namespace prompts {
|
24 |
|
25 | const prompt: any;
|
26 |
|
27 | function inject(arr: ReadonlyArray<any>): void;
|
28 |
|
29 | namespace inject {
|
30 | const prototype: {};
|
31 | }
|
32 |
|
33 | function override(obj: { [key: string]: any }): void;
|
34 |
|
35 | namespace override {
|
36 | const prototype: {};
|
37 | }
|
38 |
|
39 | namespace prompts {
|
40 | function autocomplete(args: PromptObject): any;
|
41 |
|
42 | function confirm(args: PromptObject): void;
|
43 |
|
44 | function date(args: PromptObject): any;
|
45 |
|
46 | function invisible(args: PromptObject): any;
|
47 |
|
48 | function list(args: PromptObject): any;
|
49 |
|
50 | function multiselect(args: PromptObject): any;
|
51 |
|
52 | function number(args: PromptObject): void;
|
53 |
|
54 | function password(args: PromptObject): any;
|
55 |
|
56 | function select(args: PromptObject): void;
|
57 |
|
58 | function text(args: PromptObject): void;
|
59 |
|
60 | function toggle(args: PromptObject): void;
|
61 | }
|
62 |
|
63 |
|
64 | interface Choice {
|
65 | title: string;
|
66 | value?: any;
|
67 | disabled?: boolean;
|
68 | selected?: boolean;
|
69 | description?: string;
|
70 | }
|
71 |
|
72 | interface Options {
|
73 | onSubmit?: (prompt: PromptObject, answer: any, answers: any[]) => void;
|
74 | onCancel?: (prompt: PromptObject, answers: any) => void;
|
75 | }
|
76 |
|
77 | interface PromptObject<T extends string = string> {
|
78 | type: PromptType | Falsy | PrevCaller<T, PromptType | Falsy>;
|
79 | name: ValueOrFunc<T>;
|
80 | message?: ValueOrFunc<string>;
|
81 | initial?: string | number | boolean | Date;
|
82 | style?: string | PrevCaller<T, string | Falsy>;
|
83 | format?: PrevCaller<T, void>;
|
84 | validate?: PrevCaller<T, boolean | string | Promise<boolean | string>>;
|
85 | onState?: PrevCaller<T, void>;
|
86 | min?: number | PrevCaller<T, number | Falsy>;
|
87 | max?: number | PrevCaller<T, number | Falsy>;
|
88 | float?: boolean | PrevCaller<T, boolean | Falsy>;
|
89 | round?: number | PrevCaller<T, number | Falsy>;
|
90 | instructions?: string | boolean;
|
91 | increment?: number | PrevCaller<T, number | Falsy>;
|
92 | separator?: string | PrevCaller<T, string | Falsy>;
|
93 | active?: string | PrevCaller<T, string | Falsy>;
|
94 | inactive?: string | PrevCaller<T, string | Falsy>;
|
95 | choices?: Choice[] | PrevCaller<T, Choice[] | Falsy>;
|
96 | hint?: string | PrevCaller<T, string | Falsy>;
|
97 | warn?: string | PrevCaller<T, string | Falsy>;
|
98 | suggest?: ((input: any, choices: Choice[]) => Promise<any>);
|
99 | limit?: number | PrevCaller<T, number | Falsy>;
|
100 | mask?: string | PrevCaller<T, string | Falsy>;
|
101 | stdout?: Writable;
|
102 | stdin?: Readable;
|
103 | }
|
104 |
|
105 | type Answers<T extends string> = { [id in T]: any };
|
106 |
|
107 | type PrevCaller<T extends string, R = T> = (
|
108 | prev: any,
|
109 | values: Answers<T>,
|
110 | prompt: PromptObject
|
111 | ) => R;
|
112 |
|
113 | type Falsy = false | null | undefined;
|
114 |
|
115 | type PromptType = "text" | "password" | "invisible" | "number" | "confirm" | "list" | "toggle" | "select" | "multiselect" | "autocomplete" | "date" | "autocompleteMultiselect";
|
116 |
|
117 | type ValueOrFunc<T extends string> = T | PrevCaller<T>;
|
118 | }
|