@hyperfrontend/questions 0.1.0 → 0.2.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.
- package/CHANGELOG.md +17 -1
- package/README.md +19 -7
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +7 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +5 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +4 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.cjs.js +6 -0
- package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.esm.js +5 -0
- package/index.cjs.js +175 -151
- package/index.d.ts +331 -9
- package/index.d.ts.map +1 -1
- package/index.esm.js +143 -120
- package/package.json +13 -3
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- package/render.d.ts +0 -113
- package/render.d.ts.map +0 -1
- package/terminal.d.ts +0 -109
- package/terminal.d.ts.map +0 -1
- package/types.d.ts +0 -108
- package/types.d.ts.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,12 +1,334 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Result state of a prompt interaction.
|
|
3
|
+
*/
|
|
4
|
+
declare const PromptResult: Readonly<{
|
|
5
|
+
/** User submitted a value */
|
|
6
|
+
readonly Submitted: "submitted";
|
|
7
|
+
/** User cancelled the prompt (Ctrl+C) */
|
|
8
|
+
readonly Cancelled: "cancelled";
|
|
9
|
+
}>;
|
|
10
|
+
/** Result state of a prompt interaction. */
|
|
11
|
+
type PromptResult = (typeof PromptResult)[keyof typeof PromptResult];
|
|
12
|
+
/**
|
|
13
|
+
* Base configuration shared by all prompts.
|
|
14
|
+
*/
|
|
15
|
+
interface PromptConfig {
|
|
16
|
+
/** The question message to display */
|
|
17
|
+
readonly message: string;
|
|
18
|
+
/** Stream to read input from (defaults to stdin) */
|
|
19
|
+
readonly input?: NodeJS.ReadStream;
|
|
20
|
+
/** Stream to write output to (defaults to stdout) */
|
|
21
|
+
readonly output?: NodeJS.WriteStream;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Outcome when user submits a value.
|
|
25
|
+
*/
|
|
26
|
+
interface PromptSubmittedOutcome<T> {
|
|
27
|
+
/** Submission result indicator */
|
|
28
|
+
readonly result: typeof PromptResult.Submitted;
|
|
29
|
+
/** The submitted value */
|
|
30
|
+
readonly value: T;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Outcome when user cancels the prompt.
|
|
34
|
+
*/
|
|
35
|
+
interface PromptCancelledOutcome {
|
|
36
|
+
/** Cancellation result indicator */
|
|
37
|
+
readonly result: typeof PromptResult.Cancelled;
|
|
38
|
+
/** No value on cancellation */
|
|
39
|
+
readonly value: undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Outcome of a prompt interaction.
|
|
43
|
+
*/
|
|
44
|
+
type PromptOutcome<T> = PromptSubmittedOutcome<T> | PromptCancelledOutcome;
|
|
45
|
+
/**
|
|
46
|
+
* A prompt function that asks a question and returns a value.
|
|
47
|
+
*/
|
|
48
|
+
type PromptFunction<TConfig extends PromptConfig, TValue> = (config: TConfig) => Promise<PromptOutcome<TValue>>;
|
|
49
|
+
/**
|
|
50
|
+
* Choice item for select/multiselect prompts.
|
|
51
|
+
*/
|
|
52
|
+
interface Choice<T = string> {
|
|
53
|
+
/** Display label */
|
|
54
|
+
readonly label: string;
|
|
55
|
+
/** Value returned when selected */
|
|
56
|
+
readonly value: T;
|
|
57
|
+
/** Optional hint text shown after label */
|
|
58
|
+
readonly hint?: string;
|
|
59
|
+
/** Whether this choice is disabled */
|
|
60
|
+
readonly disabled?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for text input prompts.
|
|
64
|
+
*/
|
|
65
|
+
interface TextConfig extends PromptConfig {
|
|
66
|
+
/** Default value if user submits empty input */
|
|
67
|
+
readonly initial?: string;
|
|
68
|
+
/** Validator function - return error message string to reject, undefined to accept */
|
|
69
|
+
readonly validate?: (value: string) => string | undefined;
|
|
70
|
+
/** Transform display of input (e.g., for password masking) */
|
|
71
|
+
readonly format?: (value: string) => string;
|
|
72
|
+
/** Dynamic message recomputed on every keystroke; overrides `message` when present */
|
|
73
|
+
readonly renderMessage?: (value: string) => string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Configuration for confirmation prompts.
|
|
77
|
+
*/
|
|
78
|
+
interface ConfirmConfig extends PromptConfig {
|
|
79
|
+
/** Default value if user just presses enter */
|
|
80
|
+
readonly initial?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for single-select prompts.
|
|
84
|
+
*/
|
|
85
|
+
interface SelectConfig<T = string> extends PromptConfig {
|
|
86
|
+
/** Available choices */
|
|
87
|
+
readonly choices: ReadonlyArray<Choice<T>>;
|
|
88
|
+
/** Index of initially selected choice */
|
|
89
|
+
readonly initial?: number;
|
|
90
|
+
/** Maximum number of visible choices (enables scrolling) */
|
|
91
|
+
readonly maxVisible?: number;
|
|
92
|
+
/** Enable type-to-filter */
|
|
93
|
+
readonly searchable?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configuration for multi-select prompts.
|
|
97
|
+
*/
|
|
98
|
+
interface MultiselectConfig<T = string> extends PromptConfig {
|
|
99
|
+
/** Available choices */
|
|
100
|
+
readonly choices: ReadonlyArray<Choice<T>>;
|
|
101
|
+
/** Indices of initially selected choices */
|
|
102
|
+
readonly initial?: ReadonlyArray<number>;
|
|
103
|
+
/** Maximum number of visible choices (enables scrolling) */
|
|
104
|
+
readonly maxVisible?: number;
|
|
105
|
+
/** Minimum required selections */
|
|
106
|
+
readonly min?: number;
|
|
107
|
+
/** Maximum allowed selections */
|
|
108
|
+
readonly max?: number;
|
|
109
|
+
/** Enable type-to-filter */
|
|
110
|
+
readonly searchable?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Confirmation prompt.
|
|
115
|
+
*
|
|
116
|
+
* @module @hyperfrontend/questions/prompts/confirm
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Prompts for yes/no confirmation.
|
|
121
|
+
*
|
|
122
|
+
* Pure functional prompt that asks a yes/no question and returns a boolean.
|
|
123
|
+
* Supports default values and responds to y/Y/n/N keys.
|
|
3
124
|
*
|
|
4
|
-
* @
|
|
125
|
+
* @param config - Confirm prompt configuration
|
|
126
|
+
* @returns Promise resolving to boolean value or cancellation
|
|
127
|
+
*
|
|
128
|
+
* @example Basic confirmation
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const outcome = await confirm({ message: 'Continue?' })
|
|
131
|
+
* if (outcome.result === 'submitted' && outcome.value) {
|
|
132
|
+
* console.log('Proceeding...')
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example With default value
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const outcome = await confirm({
|
|
139
|
+
* message: 'Enable feature?',
|
|
140
|
+
* initial: true, // Default to yes
|
|
141
|
+
* })
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function confirm(config: ConfirmConfig): Promise<PromptOutcome<boolean>>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Prompts for multiple selections from a list of choices.
|
|
148
|
+
*
|
|
149
|
+
* Pure functional prompt with arrow key navigation, space to toggle,
|
|
150
|
+
* scrolling support, min/max constraints, and optional type-to-filter search.
|
|
151
|
+
*
|
|
152
|
+
* @param config - Multiselect prompt configuration
|
|
153
|
+
* @returns Promise resolving to array of selected values or cancellation
|
|
154
|
+
*
|
|
155
|
+
* @example Basic multiselect
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const outcome = await multiselect({
|
|
158
|
+
* message: 'Select toppings:',
|
|
159
|
+
* choices: [
|
|
160
|
+
* { label: 'Cheese', value: 'cheese' },
|
|
161
|
+
* { label: 'Pepperoni', value: 'pepperoni' },
|
|
162
|
+
* { label: 'Mushrooms', value: 'mushrooms' },
|
|
163
|
+
* ],
|
|
164
|
+
* })
|
|
165
|
+
* if (outcome.result === 'submitted') {
|
|
166
|
+
* console.log(`You selected: ${outcome.value.join(', ')}`)
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example With search and constraints
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const outcome = await multiselect({
|
|
173
|
+
* message: 'Select features:',
|
|
174
|
+
* choices: features.map((f) => ({ label: f.name, value: f.id })),
|
|
175
|
+
* searchable: true,
|
|
176
|
+
* min: 1,
|
|
177
|
+
* max: 5,
|
|
178
|
+
* })
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @example Pre-selected values
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const outcome = await multiselect({
|
|
184
|
+
* message: 'Select permissions:',
|
|
185
|
+
* choices: permissions,
|
|
186
|
+
* initial: [0, 2], // First and third choices pre-selected
|
|
187
|
+
* })
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
declare function multiselect<T = string>(config: MultiselectConfig<T>): Promise<PromptOutcome<ReadonlyArray<T>>>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Prompts for single selection from a list of choices.
|
|
194
|
+
*
|
|
195
|
+
* Pure functional prompt with arrow key navigation, scrolling support,
|
|
196
|
+
* optional disabled choices, and optional type-to-filter search.
|
|
197
|
+
*
|
|
198
|
+
* @param config - Select prompt configuration
|
|
199
|
+
* @returns Promise resolving to selected value or cancellation
|
|
200
|
+
*
|
|
201
|
+
* @example Basic select
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const outcome = await select({
|
|
204
|
+
* message: 'Choose a color:',
|
|
205
|
+
* choices: [
|
|
206
|
+
* { label: 'Red', value: 'red' },
|
|
207
|
+
* { label: 'Green', value: 'green' },
|
|
208
|
+
* { label: 'Blue', value: 'blue' },
|
|
209
|
+
* ],
|
|
210
|
+
* })
|
|
211
|
+
* if (outcome.result === 'submitted') {
|
|
212
|
+
* console.log(`You chose: ${outcome.value}`)
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @example With hints and disabled options
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const outcome = await select({
|
|
219
|
+
* message: 'Select plan:',
|
|
220
|
+
* choices: [
|
|
221
|
+
* { label: 'Free', value: 'free', hint: '$0/month' },
|
|
222
|
+
* { label: 'Pro', value: 'pro', hint: '$10/month' },
|
|
223
|
+
* { label: 'Enterprise', value: 'enterprise', disabled: true },
|
|
224
|
+
* ],
|
|
225
|
+
* initial: 1, // Start on Pro
|
|
226
|
+
* })
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @example With search
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const outcome = await select({
|
|
232
|
+
* message: 'Pick a project:',
|
|
233
|
+
* choices: projects.map((p) => ({ label: p.name, value: p.id })),
|
|
234
|
+
* searchable: true,
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function select<T = string>(config: SelectConfig<T>): Promise<PromptOutcome<T>>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Prompts for text input with optional validation.
|
|
242
|
+
*
|
|
243
|
+
* Pure functional prompt that reads text from the user with support for
|
|
244
|
+
* default values, input validation, and display formatting.
|
|
245
|
+
*
|
|
246
|
+
* @param config - Text prompt configuration
|
|
247
|
+
* @returns Promise resolving to submitted value or cancellation
|
|
248
|
+
*
|
|
249
|
+
* @example Basic text input
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const outcome = await text({ message: 'What is your name?' })
|
|
252
|
+
* if (outcome.result === 'submitted') {
|
|
253
|
+
* console.log(`Hello, ${outcome.value}!`)
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @example With validation
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const outcome = await text({
|
|
260
|
+
* message: 'Enter email:',
|
|
261
|
+
* validate: (value) => {
|
|
262
|
+
* if (!value.includes('@')) return 'Must be a valid email'
|
|
263
|
+
* return undefined
|
|
264
|
+
* },
|
|
265
|
+
* })
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @example Password input with masking
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const outcome = await text({
|
|
271
|
+
* message: 'Password:',
|
|
272
|
+
* format: (value) => '*'.repeat(value.length),
|
|
273
|
+
* })
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
declare function text(config: TextConfig): Promise<PromptOutcome<string>>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Style functions for ANSI text formatting.
|
|
5
280
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
281
|
+
declare const style: Readonly<{
|
|
282
|
+
/**
|
|
283
|
+
* Applies bold styling to text.
|
|
284
|
+
*
|
|
285
|
+
* @param text - Text to style
|
|
286
|
+
* @returns Text wrapped in bold ANSI codes
|
|
287
|
+
*/
|
|
288
|
+
bold: (text: string) => string;
|
|
289
|
+
/**
|
|
290
|
+
* Applies dim styling to text.
|
|
291
|
+
*
|
|
292
|
+
* @param text - Text to style
|
|
293
|
+
* @returns Text wrapped in dim ANSI codes
|
|
294
|
+
*/
|
|
295
|
+
dim: (text: string) => string;
|
|
296
|
+
/**
|
|
297
|
+
* Applies cyan color to text.
|
|
298
|
+
*
|
|
299
|
+
* @param text - Text to style
|
|
300
|
+
* @returns Text wrapped in cyan ANSI codes
|
|
301
|
+
*/
|
|
302
|
+
cyan: (text: string) => string;
|
|
303
|
+
/**
|
|
304
|
+
* Applies green color to text.
|
|
305
|
+
*
|
|
306
|
+
* @param text - Text to style
|
|
307
|
+
* @returns Text wrapped in green ANSI codes
|
|
308
|
+
*/
|
|
309
|
+
green: (text: string) => string;
|
|
310
|
+
/**
|
|
311
|
+
* Applies yellow color to text.
|
|
312
|
+
*
|
|
313
|
+
* @param text - Text to style
|
|
314
|
+
* @returns Text wrapped in yellow ANSI codes
|
|
315
|
+
*/
|
|
316
|
+
yellow: (text: string) => string;
|
|
317
|
+
/**
|
|
318
|
+
* Applies red color to text.
|
|
319
|
+
*
|
|
320
|
+
* @param text - Text to style
|
|
321
|
+
* @returns Text wrapped in red ANSI codes
|
|
322
|
+
*/
|
|
323
|
+
red: (text: string) => string;
|
|
324
|
+
/**
|
|
325
|
+
* Applies gray color to text.
|
|
326
|
+
*
|
|
327
|
+
* @param text - Text to style
|
|
328
|
+
* @returns Text wrapped in gray ANSI codes
|
|
329
|
+
*/
|
|
330
|
+
gray: (text: string) => string;
|
|
331
|
+
}>;
|
|
332
|
+
|
|
333
|
+
export { PromptResult, confirm, multiselect, select, style, text };
|
|
334
|
+
export type { Choice, ConfirmConfig, MultiselectConfig, PromptCancelledOutcome, PromptConfig, PromptFunction, PromptOutcome, PromptSubmittedOutcome, SelectConfig, TextConfig };
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/questions/src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EACV,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,UAAU,GACX,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/questions/src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,EACV,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,UAAU,GACX,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
|