-
-
Notifications
You must be signed in to change notification settings - Fork 306
/
index.d.ts
120 lines (91 loc) · 4.12 KB
/
index.d.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Definitions migrated from DefinitelyTyped.
//
// Special Thanks to: Berkay GURSOY <https://github.com/Berkays>
// Daniel Perez Alvarez <https://github.com/unindented>
// Kamontat Chantrachirathumrong <https://github.com/kamontat>
// theweirdone <https://github.com/theweirdone>
// whoaa512 <https://github.com/whoaa512>
// John Reilly <https://github.com/johnnyreilly>
// Christopher Hiller <https://github.com/boneskull>
export = prompts;
import { Readable, Writable } from 'stream';
import { Kleur } from 'kleur';
declare function prompts<T extends string = string>(
questions: prompts.PromptObject<T> | Array<prompts.PromptObject<T>>,
options?: prompts.Options
): Promise<prompts.Answers<T>>;
declare namespace prompts {
// Circular reference from prompts
const prompt: any;
function inject(arr: ReadonlyArray<any>): void;
namespace inject {
const prototype: {};
}
function override(obj: { [key: string]: any }): void;
namespace override {
const prototype: {};
}
namespace prompts {
function autocomplete(args: PromptObject): any;
function confirm(args: PromptObject): void;
function date(args: PromptObject): any;
function invisible(args: PromptObject): any;
function list(args: PromptObject): any;
function multiselect(args: PromptObject): any;
function number(args: PromptObject): void;
function password(args: PromptObject): any;
function select(args: PromptObject): void;
function text(args: PromptObject): void;
function toggle(args: PromptObject): void;
}
// Based upon: https://github.com/terkelg/prompts/blob/d7d2c37a0009e3235b2e88a7d5cdbb114ac271b2/lib/elements/select.js#L29
interface Choice {
title: string;
value?: any;
disabled?: boolean | undefined;
selected?: boolean | undefined;
description?: string | undefined;
}
interface Options {
onSubmit?: ((prompt: PromptObject, answer: any, answers: any[]) => void) | undefined;
onCancel?: ((prompt: PromptObject, answers: any) => void) | undefined;
}
interface PromptObject<T extends string = string> {
type: PromptType | Falsy | PrevCaller<T, PromptType | Falsy>;
name: ValueOrFunc<T>;
message?: ValueOrFunc<string> | undefined;
initial?: InitialReturnValue | PrevCaller<T, InitialReturnValue | Promise<InitialReturnValue>> | undefined;
style?: string | PrevCaller<T, string | Falsy> | undefined;
format?: PrevCaller<T, void> | undefined;
validate?: PrevCaller<T, boolean | string | Promise<boolean | string>> | undefined;
onState?: PrevCaller<T, void> | undefined;
onRender?: ((kleur: Kleur) => void) | undefined;
min?: number | PrevCaller<T, number | Falsy> | undefined;
max?: number | PrevCaller<T, number | Falsy> | undefined;
float?: boolean | PrevCaller<T, boolean | Falsy> | undefined;
round?: number | PrevCaller<T, number | Falsy> | undefined;
instructions?: string | boolean | undefined;
increment?: number | PrevCaller<T, number | Falsy> | undefined;
separator?: string | PrevCaller<T, string | Falsy> | undefined;
active?: string | PrevCaller<T, string | Falsy> | undefined;
inactive?: string | PrevCaller<T, string | Falsy> | undefined;
choices?: Choice[] | PrevCaller<T, Choice[] | Falsy> | undefined;
hint?: string | PrevCaller<T, string | Falsy> | undefined;
warn?: string | PrevCaller<T, string | Falsy> | undefined;
suggest?: ((input: any, choices: Choice[]) => Promise<any>) | undefined;
limit?: number | PrevCaller<T, number | Falsy> | undefined;
mask?: string | PrevCaller<T, string | Falsy> | undefined;
stdout?: Writable | undefined;
stdin?: Readable | undefined;
}
type Answers<T extends string> = { [id in T]: any };
type PrevCaller<T extends string, R = T> = (
prev: any,
values: Answers<T>,
prompt: PromptObject
) => R;
type Falsy = false | null | undefined;
type PromptType = "text" | "password" | "invisible" | "number" | "confirm" | "list" | "toggle" | "select" | "multiselect" | "autocomplete" | "date" | "autocompleteMultiselect";
type ValueOrFunc<T extends string> = T | PrevCaller<T>;
type InitialReturnValue = string | number | boolean | Date;
}