index.d.ts
2.93 KB
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
// Type definitions for prompts 2.0
// Project: https://github.com/terkelg/prompts
// Definitions by: Berkay GURSOY <https://github.com/Berkays>
// Daniel Perez Alvarez <https://github.com/danielpa9708>
// Kamontat Chantrachirathumrong <https://github.com/kamontat>
// theweirdone <https://github.com/theweirdone>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
export = prompts;
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(obj: any): void;
namespace inject {
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;
}
interface Choice {
title: string;
value: string;
disable?: boolean;
}
interface Options {
onSubmit?: (prompt: PromptObject, answer: any, answers: any[]) => void;
onCancel?: (prompt: PromptObject, answers: any) => void;
}
interface PromptObject<T extends string = string> {
type: PromptType | Falsy | PrevCaller<T, PromptType | Falsy>;
name: ValueOrFunc<T>;
message?: ValueOrFunc<string>;
initial?: string | number | boolean | Date;
style?: string;
format?: PrevCaller<T, void>;
validate?: PrevCaller<T, boolean | string>;
onState?: PrevCaller<T, void>;
min?: number;
max?: number;
float?: boolean;
round?: number;
increment?: number;
seperator?: string;
active?: string;
inactive?: string;
choices?: Choice[];
hint?: string;
suggest?: ((prev: any, values: any, prompt: PromptObject) => void);
limit?: number;
mask?: string;
}
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>;
}