-
-
Notifications
You must be signed in to change notification settings - Fork 793
/
types.d.ts
180 lines (147 loc) · 4.85 KB
/
types.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* PackageJson declaration type.
* for import package.js as ESM without having to participate in compilation
* declarations.d.ts
*/
declare module '*/package.json' {
export const name: string
export const version: string
}
declare module 'prompts' {
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/prompts/index.d.ts
import { Readable, Writable } from 'stream'
export = prompts
interface Color {
(x: string | number): string
(): Kleur
}
interface Kleur {
// Colors
black: Color
red: Color
green: Color
yellow: Color
blue: Color
magenta: Color
cyan: Color
white: Color
gray: Color
grey: Color
// Backgrounds
bgBlack: Color
bgRed: Color
bgGreen: Color
bgYellow: Color
bgBlue: Color
bgMagenta: Color
bgCyan: Color
bgWhite: Color
// Modifiers
reset: Color
bold: Color
dim: Color
italic: Color
underline: Color
inverse: Color
hidden: Color
strikethrough: Color
}
function prompts<T extends string = string> (
questions: prompts.PromptObject<T> | Array<prompts.PromptObject<T>>,
options?: prompts.Options
): Promise<prompts.Answers<T>>
namespace prompts {
// Circular reference from prompts
const prompt: any
function inject (arr: readonly 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
}
}