@decaf-ts/utils 0.1.6

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.
Files changed (112) hide show
  1. package/LICENSE.md +157 -0
  2. package/README.md +95 -0
  3. package/dist/esm/utils.js +1 -0
  4. package/dist/types/bin/tag-release.d.ts +1 -0
  5. package/dist/types/bin/update-scripts.d.ts +1 -0
  6. package/dist/types/cli/command.d.ts +110 -0
  7. package/dist/types/cli/commands/index.d.ts +2 -0
  8. package/dist/types/cli/commands/tag-release.d.ts +105 -0
  9. package/dist/types/cli/commands/update-scripts.d.ts +211 -0
  10. package/dist/types/cli/constants.d.ts +73 -0
  11. package/dist/types/cli/index.d.ts +4 -0
  12. package/dist/types/cli/types.d.ts +28 -0
  13. package/dist/types/index.d.ts +39 -0
  14. package/dist/types/input/index.d.ts +2 -0
  15. package/dist/types/input/input.d.ts +472 -0
  16. package/dist/types/input/types.d.ts +76 -0
  17. package/dist/types/output/common.d.ts +51 -0
  18. package/dist/types/output/index.d.ts +3 -0
  19. package/dist/types/output/logging.d.ts +177 -0
  20. package/dist/types/output/types.d.ts +203 -0
  21. package/dist/types/utils/accumulator.d.ts +105 -0
  22. package/dist/types/utils/constants.d.ts +136 -0
  23. package/dist/types/utils/environment.d.ts +57 -0
  24. package/dist/types/utils/fs.d.ts +133 -0
  25. package/dist/types/utils/http.d.ts +41 -0
  26. package/dist/types/utils/index.d.ts +7 -0
  27. package/dist/types/utils/md.d.ts +156 -0
  28. package/dist/types/utils/tests.d.ts +170 -0
  29. package/dist/types/utils/text.d.ts +106 -0
  30. package/dist/types/utils/timeout.d.ts +1 -0
  31. package/dist/types/utils/types.d.ts +81 -0
  32. package/dist/types/utils/utils.d.ts +91 -0
  33. package/dist/types/utils/web.d.ts +7 -0
  34. package/dist/types/writers/OutputWriter.d.ts +49 -0
  35. package/dist/types/writers/RegexpOutputWriter.d.ts +69 -0
  36. package/dist/types/writers/StandardOutputWriter.d.ts +91 -0
  37. package/dist/types/writers/index.d.ts +4 -0
  38. package/dist/types/writers/types.d.ts +29 -0
  39. package/dist/utils.js +1 -0
  40. package/lib/assets/slogans.json +802 -0
  41. package/lib/bin/tag-release.cjs +12 -0
  42. package/lib/bin/update-scripts.cjs +12 -0
  43. package/lib/cli/command.cjs +153 -0
  44. package/lib/cli/commands/index.cjs +20 -0
  45. package/lib/cli/commands/tag-release.cjs +168 -0
  46. package/lib/cli/commands/update-scripts.cjs +511 -0
  47. package/lib/cli/constants.cjs +80 -0
  48. package/lib/cli/index.cjs +22 -0
  49. package/lib/cli/types.cjs +4 -0
  50. package/lib/esm/assets/slogans.json +802 -0
  51. package/lib/esm/bin/tag-release.js +10 -0
  52. package/lib/esm/bin/update-scripts.js +10 -0
  53. package/lib/esm/cli/command.js +149 -0
  54. package/lib/esm/cli/commands/index.js +4 -0
  55. package/lib/esm/cli/commands/tag-release.js +164 -0
  56. package/lib/esm/cli/commands/update-scripts.js +504 -0
  57. package/lib/esm/cli/constants.js +77 -0
  58. package/lib/esm/cli/index.js +6 -0
  59. package/lib/esm/cli/types.js +3 -0
  60. package/lib/esm/index.js +41 -0
  61. package/lib/esm/input/index.js +4 -0
  62. package/lib/esm/input/input.js +570 -0
  63. package/lib/esm/input/types.js +3 -0
  64. package/lib/esm/output/common.js +93 -0
  65. package/lib/esm/output/index.js +5 -0
  66. package/lib/esm/output/logging.js +350 -0
  67. package/lib/esm/output/types.js +3 -0
  68. package/lib/esm/utils/accumulator.js +145 -0
  69. package/lib/esm/utils/constants.js +176 -0
  70. package/lib/esm/utils/environment.js +91 -0
  71. package/lib/esm/utils/fs.js +271 -0
  72. package/lib/esm/utils/http.js +70 -0
  73. package/lib/esm/utils/index.js +9 -0
  74. package/lib/esm/utils/md.js +3 -0
  75. package/lib/esm/utils/tests.js +223 -0
  76. package/lib/esm/utils/text.js +142 -0
  77. package/lib/esm/utils/timeout.js +5 -0
  78. package/lib/esm/utils/types.js +3 -0
  79. package/lib/esm/utils/utils.js +220 -0
  80. package/lib/esm/utils/web.js +12 -0
  81. package/lib/esm/writers/OutputWriter.js +3 -0
  82. package/lib/esm/writers/RegexpOutputWriter.js +98 -0
  83. package/lib/esm/writers/StandardOutputWriter.js +127 -0
  84. package/lib/esm/writers/index.js +6 -0
  85. package/lib/esm/writers/types.js +3 -0
  86. package/lib/index.cjs +58 -0
  87. package/lib/input/index.cjs +20 -0
  88. package/lib/input/input.cjs +577 -0
  89. package/lib/input/types.cjs +4 -0
  90. package/lib/output/common.cjs +100 -0
  91. package/lib/output/index.cjs +21 -0
  92. package/lib/output/logging.cjs +355 -0
  93. package/lib/output/types.cjs +4 -0
  94. package/lib/utils/accumulator.cjs +149 -0
  95. package/lib/utils/constants.cjs +179 -0
  96. package/lib/utils/environment.cjs +95 -0
  97. package/lib/utils/fs.cjs +288 -0
  98. package/lib/utils/http.cjs +77 -0
  99. package/lib/utils/index.cjs +25 -0
  100. package/lib/utils/md.cjs +4 -0
  101. package/lib/utils/tests.cjs +263 -0
  102. package/lib/utils/text.cjs +153 -0
  103. package/lib/utils/timeout.cjs +8 -0
  104. package/lib/utils/types.cjs +4 -0
  105. package/lib/utils/utils.cjs +226 -0
  106. package/lib/utils/web.cjs +15 -0
  107. package/lib/writers/OutputWriter.cjs +4 -0
  108. package/lib/writers/RegexpOutputWriter.cjs +102 -0
  109. package/lib/writers/StandardOutputWriter.cjs +131 -0
  110. package/lib/writers/index.cjs +22 -0
  111. package/lib/writers/types.cjs +4 -0
  112. package/package.json +121 -0
@@ -0,0 +1,472 @@
1
+ import prompts, { Choice, Falsy, InitialReturnValue, PrevCaller, PromptObject, PromptType, ValueOrFunc } from "prompts";
2
+ import { Writable, Readable } from "stream";
3
+ import { Kleur } from "../output/types";
4
+ import { ParseArgsOptionsConfig, ParseArgsResult } from "./types";
5
+ /**
6
+ * @description Represents a user input prompt with various configuration options.
7
+ * @summary This class provides a flexible interface for creating and managing user input prompts.
8
+ * It implements the PromptObject interface from the 'prompts' library and offers methods to set
9
+ * various properties of the prompt. The class also includes static methods for common input scenarios
10
+ * and argument parsing.
11
+ *
12
+ * @template R - The type of the prompt name, extending string.
13
+ *
14
+ * @param name - The name of the prompt, used as the key in the returned answers object.
15
+ *
16
+ * @class
17
+ */
18
+ export declare class UserInput<R extends string = string> implements PromptObject<R> {
19
+ private static readonly logger;
20
+ /**
21
+ * @description The type of the prompt.
22
+ * @summary Determines the input method (e.g., text, number, confirm).
23
+ */
24
+ type: PromptType | Falsy | PrevCaller<R, PromptType | Falsy>;
25
+ /**
26
+ * @description The name of the prompt.
27
+ * @summary Used as the key in the returned answers object.
28
+ */
29
+ name: ValueOrFunc<R>;
30
+ /**
31
+ * @description The message displayed to the user.
32
+ * @summary The question or instruction presented to the user.
33
+ */
34
+ message?: ValueOrFunc<string> | undefined;
35
+ /**
36
+ * @description The initial value of the prompt.
37
+ * @summary The default value presented to the user.
38
+ */
39
+ initial?: InitialReturnValue | PrevCaller<R, InitialReturnValue | Promise<InitialReturnValue>> | undefined;
40
+ /**
41
+ * @description The style of the prompt.
42
+ * @summary Determines the visual style of the prompt.
43
+ */
44
+ style?: string | PrevCaller<R, string | Falsy> | undefined;
45
+ /**
46
+ * @description The format function for the input.
47
+ * @summary A function to format the user's input before it's returned.
48
+ */
49
+ format?: PrevCaller<R, void> | undefined;
50
+ /**
51
+ * @description The validation function for the input.
52
+ * @summary A function to validate the user's input.
53
+ */
54
+ validate?: PrevCaller<R, boolean | string | Promise<boolean | string>> | undefined;
55
+ /**
56
+ * @description The onState callback function.
57
+ * @summary A function called when the state of the prompt changes.
58
+ */
59
+ onState?: PrevCaller<R, void> | undefined;
60
+ onRender?: ((kleur: Kleur) => void) | undefined;
61
+ /**
62
+ * @description The minimum value for number inputs.
63
+ * @summary The lowest number the user can input.
64
+ */
65
+ min?: number | PrevCaller<R, number | Falsy> | undefined;
66
+ /**
67
+ * @description The maximum value for number inputs.
68
+ * @summary The highest number the user can input.
69
+ */
70
+ max?: number | PrevCaller<R, number | Falsy> | undefined;
71
+ /**
72
+ * @description Whether to allow float values for number inputs.
73
+ * @summary If true, allows decimal numbers.
74
+ */
75
+ float?: boolean | PrevCaller<R, boolean | Falsy> | undefined;
76
+ /**
77
+ * @description The number of decimal places to round to for float inputs.
78
+ * @summary Determines the precision of float inputs.
79
+ */
80
+ round?: number | PrevCaller<R, number | Falsy> | undefined;
81
+ /**
82
+ * @description Instructions for the user.
83
+ * @summary Additional guidance provided to the user.
84
+ */
85
+ instructions?: string | boolean | undefined;
86
+ /**
87
+ * @description The increment value for number inputs.
88
+ * @summary The step size when increasing or decreasing the number.
89
+ */
90
+ increment?: number | PrevCaller<R, number | Falsy> | undefined;
91
+ /**
92
+ * @description The separator for list inputs.
93
+ * @summary The character used to separate list items.
94
+ */
95
+ separator?: string | PrevCaller<R, string | Falsy> | undefined;
96
+ /**
97
+ * @description The active option style for select inputs.
98
+ * @summary The style applied to the currently selected option.
99
+ */
100
+ active?: string | PrevCaller<R, string | Falsy> | undefined;
101
+ /**
102
+ * @description The inactive option style for select inputs.
103
+ * @summary The style applied to non-selected options.
104
+ */
105
+ inactive?: string | PrevCaller<R, string | Falsy> | undefined;
106
+ choices?: Choice[] | PrevCaller<R, Choice[] | Falsy> | undefined;
107
+ /**
108
+ * @description The hint text for the prompt.
109
+ * @summary Additional information displayed to the user.
110
+ */
111
+ hint?: string | PrevCaller<R, string | Falsy> | undefined;
112
+ /**
113
+ * @description The warning text for the prompt.
114
+ * @summary A warning message displayed to the user.
115
+ */
116
+ warn?: string | PrevCaller<R, string | Falsy> | undefined;
117
+ suggest?: ((input: any, choices: Choice[]) => Promise<any>) | undefined;
118
+ /**
119
+ * @description The limit for list inputs.
120
+ * @summary The maximum number of items that can be selected.
121
+ */
122
+ limit?: number | PrevCaller<R, number | Falsy> | undefined;
123
+ /**
124
+ * @description The mask for password inputs.
125
+ * @summary The character used to hide the user's input.
126
+ */
127
+ mask?: string | PrevCaller<R, string | Falsy> | undefined;
128
+ /**
129
+ * @description The stdout stream for the prompt.
130
+ * @summary The output stream used by the prompt.
131
+ */
132
+ stdout?: Writable | undefined;
133
+ /**
134
+ * @description The stdin stream for the prompt.
135
+ * @summary The input stream used by the prompt.
136
+ */
137
+ stdin?: Readable | undefined;
138
+ /**
139
+ * @description Creates a new UserInput instance.
140
+ * @summary Initializes a new UserInput object with the given name.
141
+ *
142
+ * @param name - The name of the prompt.
143
+ */
144
+ constructor(name: ValueOrFunc<R>);
145
+ /**
146
+ * @description Sets the type of the prompt.
147
+ * @summary Configures the input method for the prompt.
148
+ *
149
+ * @param type - The type of the prompt.
150
+ * @returns This UserInput instance for method chaining.
151
+ */
152
+ setType(type: PromptType | Falsy | PrevCaller<R, PromptType | Falsy>): this;
153
+ /**
154
+ * @description Sets the message of the prompt.
155
+ * @summary Configures the question or instruction presented to the user.
156
+ *
157
+ * @param value - The message to be displayed.
158
+ * @returns This UserInput instance for method chaining.
159
+ */
160
+ setMessage(value: ValueOrFunc<string> | undefined): this;
161
+ /**
162
+ * @description Sets the initial value of the prompt.
163
+ * @summary Configures the default value presented to the user.
164
+ *
165
+ * @param value - The initial value.
166
+ * @returns This UserInput instance for method chaining.
167
+ */
168
+ setInitial(value: InitialReturnValue | PrevCaller<R, InitialReturnValue | Promise<InitialReturnValue>> | undefined): this;
169
+ /**
170
+ * @description Sets the style of the prompt.
171
+ * @summary Configures the visual style of the prompt.
172
+ *
173
+ * @param value - The style to be applied.
174
+ * @returns This UserInput instance for method chaining.
175
+ */
176
+ setStyle(value: string | PrevCaller<R, string | Falsy> | undefined): this;
177
+ /**
178
+ * @description Sets the format function of the prompt.
179
+ * @summary Configures a function to format the user's input before it's returned.
180
+ *
181
+ * @param value - The format function.
182
+ * @returns This UserInput instance for method chaining.
183
+ */
184
+ setFormat(value: PrevCaller<R, void> | undefined): this;
185
+ /**
186
+ * @description Sets the validation function of the prompt.
187
+ * @summary Configures a function to validate the user's input.
188
+ *
189
+ * @param value - The validation function.
190
+ * @returns This UserInput instance for method chaining.
191
+ */
192
+ setValidate(value: PrevCaller<R, boolean | string | Promise<boolean | string>> | undefined): this;
193
+ /**
194
+ * @description Sets the onState callback of the prompt.
195
+ * @summary Configures a function to be called when the state of the prompt changes.
196
+ *
197
+ * @param value - The onState callback function.
198
+ * @returns This UserInput instance for method chaining.
199
+ */
200
+ setOnState(value: PrevCaller<R, void> | undefined): this;
201
+ /**
202
+ * @description Sets the onRender callback of the prompt.
203
+ * @summary Configures a function to be called when the prompt is rendered.
204
+ *
205
+ * @param value - The onRender callback function.
206
+ * @returns This UserInput instance for method chaining.
207
+ */
208
+ setOnRender(value: ((kleur: Kleur) => void) | undefined): this;
209
+ /**
210
+ * @description Sets the minimum value for number inputs.
211
+ * @summary Configures the lowest number the user can input.
212
+ *
213
+ * @param value - The minimum value.
214
+ * @returns This UserInput instance for method chaining.
215
+ */
216
+ setMin(value: number | PrevCaller<R, number | Falsy> | undefined): this;
217
+ /**
218
+ * @description Sets the maximum value for number inputs.
219
+ * @summary Configures the highest number the user can input.
220
+ *
221
+ * @param value - The maximum value.
222
+ * @returns This UserInput instance for method chaining.
223
+ */
224
+ setMax(value: number | PrevCaller<R, number | Falsy> | undefined): this;
225
+ /**
226
+ * @description Sets whether to allow float values for number inputs.
227
+ * @summary Configures whether decimal numbers are allowed.
228
+ *
229
+ * @param value - Whether to allow float values.
230
+ * @returns This UserInput instance for method chaining.
231
+ */
232
+ setFloat(value: boolean | PrevCaller<R, boolean | Falsy> | undefined): this;
233
+ /**
234
+ * @description Sets the number of decimal places to round to for float inputs.
235
+ * @summary Configures the precision of float inputs.
236
+ *
237
+ * @param value - The number of decimal places.
238
+ * @returns This UserInput instance for method chaining.
239
+ */
240
+ setRound(value: number | PrevCaller<R, number | Falsy> | undefined): this;
241
+ /**
242
+ * @description Sets the instructions for the user.
243
+ * @summary Configures additional guidance provided to the user.
244
+ *
245
+ * @param value - The instructions.
246
+ * @returns This UserInput instance for method chaining.
247
+ */
248
+ setInstructions(value: string | boolean | undefined): this;
249
+ /**
250
+ * @description Sets the increment value for number inputs.
251
+ * @summary Configures the step size when increasing or decreasing the number.
252
+ *
253
+ * @param value - The increment value.
254
+ * @returns This UserInput instance for method chaining.
255
+ */
256
+ setIncrement(value: number | PrevCaller<R, number | Falsy> | undefined): this;
257
+ /**
258
+ * @description Sets the separator for list inputs.
259
+ * @summary Configures the character used to separate list items.
260
+ *
261
+ * @param value - The separator character.
262
+ * @returns This UserInput instance for method chaining.
263
+ */
264
+ setSeparator(value: string | PrevCaller<R, string | Falsy> | undefined): this;
265
+ /**
266
+ * @description Sets the active option style for select inputs.
267
+ * @summary Configures the style applied to the currently selected option.
268
+ *
269
+ * @param value - The active option style.
270
+ * @returns This UserInput instance for method chaining.
271
+ */
272
+ setActive(value: string | PrevCaller<R, string | Falsy> | undefined): this;
273
+ /**
274
+ * @description Sets the inactive option style for select inputs.
275
+ * @summary Configures the style applied to non-selected options.
276
+ *
277
+ * @param value - The inactive option style.
278
+ * @returns This UserInput instance for method chaining.
279
+ */
280
+ setInactive(value: string | PrevCaller<R, string | Falsy> | undefined): this;
281
+ setChoices(value: Choice[] | PrevCaller<R, Choice[] | Falsy> | undefined): this;
282
+ /**
283
+ * @description Sets the hint text for the prompt.
284
+ * @summary Configures additional information displayed to the user.
285
+ *
286
+ * @param value - The hint text.
287
+ * @returns This UserInput instance for method chaining.
288
+ */
289
+ setHint(value: string | PrevCaller<R, string | Falsy> | undefined): this;
290
+ /**
291
+ * @description Sets the warning text for the prompt.
292
+ * @summary Configures a warning message displayed to the user.
293
+ *
294
+ * @param value - The warning text.
295
+ * @returns This UserInput instance for method chaining.
296
+ */
297
+ setWarn(value: string | PrevCaller<R, string | Falsy> | undefined): this;
298
+ setSuggest(value: ((input: any, choices: Choice[]) => Promise<any>) | undefined): this;
299
+ /**
300
+ * @description Sets the limit for list inputs.
301
+ * @summary Configures the maximum number of items that can be selected in list-type prompts.
302
+ * @template R - The type of the prompt name, extending string.
303
+ * @param value - The maximum number of items that can be selected, or a function to determine this value.
304
+ * @return This UserInput instance for method chaining.
305
+ */
306
+ setLimit(value: number | PrevCaller<R, number | Falsy> | undefined): this;
307
+ /**
308
+ * @description Sets the mask for password inputs.
309
+ * @summary Configures the character used to hide the user's input in password-type prompts.
310
+ * @template R - The type of the prompt name, extending string.
311
+ * @param value - The character used to mask the input, or a function to determine this value.
312
+ * @return This UserInput instance for method chaining.
313
+ */
314
+ setMask(value: string | PrevCaller<R, string | Falsy> | undefined): this;
315
+ /**
316
+ * @description Sets the stdout stream for the prompt.
317
+ * @summary Configures the output stream used by the prompt for displaying messages and results.
318
+ * @param value - The Writable stream to be used as stdout.
319
+ * @return This UserInput instance for method chaining.
320
+ */
321
+ setStdout(value: Writable | undefined): this;
322
+ /**
323
+ * @description Sets the stdin stream for the prompt.
324
+ * @summary Configures the input stream used by the prompt for receiving user input.
325
+ * @param value - The Readable stream to be used as stdin.
326
+ * @return This UserInput instance for method chaining.
327
+ */
328
+ setStdin(value: Readable | undefined): this;
329
+ /**
330
+ * @description Asks the user for input based on the current UserInput configuration.
331
+ * @summary Prompts the user and returns their response as a single value.
332
+ * @template R - The type of the prompt name, extending string.
333
+ * @return A Promise that resolves to the user's answer.
334
+ */
335
+ ask(): Promise<prompts.Answers<R>[R]>;
336
+ /**
337
+ * @description Asks the user one or more questions based on the provided UserInput configurations.
338
+ * @summary Prompts the user with one or more questions and returns their answers as an object.
339
+ * @template R - The type of the prompt name, extending string.
340
+ * @param question - A single UserInput instance or an array of UserInput instances.
341
+ * @return A Promise that resolves to an object containing the user's answers.
342
+ * @mermaid
343
+ * sequenceDiagram
344
+ * participant U as User
345
+ * participant A as ask method
346
+ * participant P as prompts library
347
+ * A->>P: Call prompts with question(s)
348
+ * P->>U: Display prompt(s)
349
+ * U->>P: Provide input
350
+ * P->>A: Return answers
351
+ * A->>A: Process answers
352
+ * A-->>Caller: Return processed answers
353
+ */
354
+ static ask<R extends string = string>(question: UserInput<R> | UserInput<R>[]): Promise<prompts.Answers<R>>;
355
+ /**
356
+ * @description Asks the user for a number input.
357
+ * @summary Prompts the user to enter a number, with optional minimum, maximum, and initial values.
358
+ * @param name - The name of the prompt, used as the key in the returned answers object.
359
+ * @param question - The message displayed to the user.
360
+ * @param min - The minimum allowed value (optional).
361
+ * @param max - The maximum allowed value (optional).
362
+ * @param initial - The initial value presented to the user (optional).
363
+ * @return A Promise that resolves to the number entered by the user.
364
+ */
365
+ static askNumber(name: string, question: string, min?: number, max?: number, initial?: number): Promise<number>;
366
+ /**
367
+ * @description Asks the user for a text input.
368
+ * @summary Prompts the user to enter text, with optional masking and initial value.
369
+ * @param name - The name of the prompt, used as the key in the returned answers object.
370
+ * @param question - The message displayed to the user.
371
+ * @param mask - The character used to mask the input (optional, for password-like inputs).
372
+ * @param initial - The initial value presented to the user (optional).
373
+ * @return A Promise that resolves to the text entered by the user.
374
+ */
375
+ static askText(name: string, question: string, mask?: string | undefined, initial?: string): Promise<string>;
376
+ /**
377
+ * @description Asks the user for a confirmation (yes/no).
378
+ * @summary Prompts the user with a yes/no question and returns a boolean result.
379
+ * @param name - The name of the prompt, used as the key in the returned answers object.
380
+ * @param question - The message displayed to the user.
381
+ * @param initial - The initial value presented to the user (optional).
382
+ * @return A Promise that resolves to a boolean representing the user's answer.
383
+ */
384
+ static askConfirmation(name: string, question: string, initial?: boolean): Promise<boolean>;
385
+ /**
386
+ * @description Repeatedly asks for input until a valid response is given or the limit is reached.
387
+ * @summary This method insists on getting a valid input from the user, allowing for a specified number of attempts.
388
+ *
389
+ * @template R - The type of the expected result.
390
+ * @param input - The UserInput instance to use for prompting.
391
+ * @param test - A function to validate the user's input.
392
+ * @param limit - The maximum number of attempts allowed (default is 1).
393
+ * @param defaultConfirmation
394
+ * @return A Promise that resolves to the valid input or undefined if the limit is reached.
395
+ *
396
+ * @mermaid
397
+ * sequenceDiagram
398
+ * participant U as User
399
+ * participant I as insist method
400
+ * participant A as ask method
401
+ * participant T as test function
402
+ * participant C as askConfirmation method
403
+ * loop Until valid input or limit reached
404
+ * I->>A: Call ask with input
405
+ * A->>U: Prompt user
406
+ * U->>A: Provide input
407
+ * A->>I: Return result
408
+ * I->>T: Test result
409
+ * alt Test passes
410
+ * I->>C: Ask for confirmation
411
+ * C->>U: Confirm input
412
+ * U->>C: Provide confirmation
413
+ * C->>I: Return confirmation
414
+ * alt Confirmed
415
+ * I-->>Caller: Return valid result
416
+ * else Not confirmed
417
+ * I->>I: Continue loop
418
+ * end
419
+ * else Test fails
420
+ * I->>I: Continue loop
421
+ * end
422
+ * end
423
+ * I-->>Caller: Return undefined if limit reached
424
+ */
425
+ static insist<R>(input: UserInput, test: (res: string | number) => boolean, defaultConfirmation: boolean, limit?: number): Promise<R | undefined>;
426
+ /**
427
+ * @description Repeatedly asks for text input until a valid response is given or the limit is reached.
428
+ * @summary This method insists on getting a valid text input from the user, allowing for a specified number of attempts.
429
+ *
430
+ * @param name - The name of the prompt, used as the key in the returned answers object.
431
+ * @param question - The message displayed to the user.
432
+ * @param test - A function to validate the user's input.
433
+ * @param mask - The character used to mask the input (optional, for password-like inputs).
434
+ * @param initial - The initial value presented to the user (optional).
435
+ * @param defaultConfirmation
436
+ * @param limit - The maximum number of attempts allowed (default is -1, meaning unlimited).
437
+ * @return A Promise that resolves to the valid input or undefined if the limit is reached.
438
+ */
439
+ static insistForText(name: string, question: string, test: (res: string) => boolean, mask?: string | undefined, initial?: string, defaultConfirmation?: boolean, limit?: number): Promise<string>;
440
+ /**
441
+ * @description Repeatedly asks for number input until a valid response is given or the limit is reached.
442
+ * @summary This method insists on getting a valid number input from the user, allowing for a specified number of attempts.
443
+ *
444
+ * @param name - The name of the prompt, used as the key in the returned answers object.
445
+ * @param question - The message displayed to the user.
446
+ * @param test - A function to validate the user's input.
447
+ * @param min - The minimum allowed value (optional).
448
+ * @param max - The maximum allowed value (optional).
449
+ * @param initial - The initial value presented to the user (optional).
450
+ * @param defaultConfirmation
451
+ * @param limit - The maximum number of attempts allowed (default is -1, meaning unlimited).
452
+ * @return A Promise that resolves to the valid input or undefined if the limit is reached.
453
+ */
454
+ static insistForNumber(name: string, question: string, test: (res: number) => boolean, min?: number, max?: number, initial?: number, defaultConfirmation?: boolean, limit?: number): Promise<number>;
455
+ /**
456
+ * @description Parses command-line arguments based on the provided options.
457
+ * @summary Uses Node.js's util.parseArgs to parse command-line arguments and return the result.
458
+ * @param options - Configuration options for parsing arguments.
459
+ * @return An object containing the parsed arguments.
460
+ * @mermaid
461
+ * sequenceDiagram
462
+ * participant C as Caller
463
+ * participant P as parseArgs method
464
+ * participant U as util.parseArgs
465
+ * C->>P: Call with options
466
+ * P->>P: Prepare args object
467
+ * P->>U: Call parseArgs with prepared args
468
+ * U->>P: Return parsed result
469
+ * P-->>C: Return ParseArgsResult
470
+ */
471
+ static parseArgs(options: ParseArgsOptionsConfig): ParseArgsResult;
472
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @description Configuration for a single command-line argument option.
3
+ * @summary Defines the structure and behavior of a command-line option.
4
+ * @interface ParseArgsOptionConfig
5
+ * @property {("string" | "boolean")} type - The data type of the option.
6
+ * @property {boolean} [multiple] - Whether the option can be specified multiple times.
7
+ * @property {string} [short] - The short (single-character) alias for the option.
8
+ * @property {string | boolean | string[] | boolean[]} [default] - The default value(s) for the option.
9
+ * @memberOf @decaf-ts/utils
10
+ */
11
+ export interface ParseArgsOptionConfig {
12
+ type: "string" | "boolean";
13
+ multiple?: boolean | undefined;
14
+ short?: string | undefined;
15
+ default?: string | boolean | string[] | boolean[] | undefined;
16
+ }
17
+ /**
18
+ * @description Configuration for all command-line argument options.
19
+ * @summary A mapping of long option names to their configurations.
20
+ * @interface ParseArgsOptionsConfig
21
+ * @memberOf @decaf-ts/utils
22
+ */
23
+ export interface ParseArgsOptionsConfig {
24
+ [longOption: string]: ParseArgsOptionConfig;
25
+ }
26
+ /**
27
+ * @description Represents a parsed command-line option token.
28
+ * @summary Can be either an option with a value or an option without a value.
29
+ * @typedef {Object} OptionToken
30
+ * @memberOf @decaf-ts/utils
31
+ */
32
+ export type OptionToken = {
33
+ kind: "option";
34
+ index: number;
35
+ name: string;
36
+ rawName: string;
37
+ value: string;
38
+ inlineValue: boolean;
39
+ } | {
40
+ kind: "option";
41
+ index: number;
42
+ name: string;
43
+ rawName: string;
44
+ value: undefined;
45
+ inlineValue: undefined;
46
+ };
47
+ /**
48
+ * @description Represents a parsed command-line token.
49
+ * @summary Can be an option, a positional argument, or an option terminator.
50
+ * @typedef {OptionToken | Object} Token
51
+ * @memberOf @decaf-ts/utils
52
+ */
53
+ export type Token = OptionToken | {
54
+ kind: "positional";
55
+ index: number;
56
+ value: string;
57
+ } | {
58
+ kind: "option-terminator";
59
+ index: number;
60
+ };
61
+ /**
62
+ * @description The result of parsing command-line arguments.
63
+ * @summary Contains parsed values, positional arguments, and optionally the parsed tokens.
64
+ * @typedef {Object} ParseArgsResult
65
+ * @property {string | boolean | string[] | boolean[] | undefined} values - Parsed option values.
66
+ * @property {string[]} positionals - Positional arguments.
67
+ * @property {Token[]} [tokens] - Parsed tokens (if requested).
68
+ * @memberOf @decaf-ts/utils
69
+ */
70
+ export type ParseArgsResult = {
71
+ values: {
72
+ [p: string]: string | boolean | (string | boolean)[] | undefined;
73
+ };
74
+ positionals: string[];
75
+ tokens?: Token[];
76
+ };
@@ -0,0 +1,51 @@
1
+ import { VerbosityLogger } from "./types";
2
+ /**
3
+ * @description Prints a styled banner to the console.
4
+ * @summary Generates and prints a colorful ASCII art banner with a random slogan.
5
+ * @param {VerbosityLogger} [logger] - Optional logger for verbose output.
6
+ * @function printBanner
7
+ * @mermaid
8
+ * sequenceDiagram
9
+ * participant printBanner
10
+ * participant getSlogan
11
+ * participant padEnd
12
+ * participant console
13
+ * printBanner->>getSlogan: Call getSlogan()
14
+ * getSlogan-->>printBanner: Return random slogan
15
+ * printBanner->>printBanner: Create banner ASCII art
16
+ * printBanner->>printBanner: Split banner into lines
17
+ * printBanner->>printBanner: Calculate max line length
18
+ * printBanner->>padEnd: Call padEnd with slogan
19
+ * padEnd-->>printBanner: Return padded slogan line
20
+ * loop For each banner line
21
+ * printBanner->>style: Call style(line)
22
+ * style-->>printBanner: Return styled line
23
+ * printBanner->>console: Log styled line
24
+ * end
25
+ */
26
+ export declare function printBanner(logger?: VerbosityLogger): void;
27
+ /**
28
+ * @description Retrieves a slogan from the predefined list.
29
+ * @summary Fetches a random slogan or a specific one by index from the slogans list.
30
+ * @param {number} [i] - Optional index to retrieve a specific slogan.
31
+ * @return {string} The selected slogan.
32
+ * @function getSlogan
33
+ * @mermaid
34
+ * sequenceDiagram
35
+ * participant getSlogan
36
+ * participant Math.random
37
+ * participant slogans
38
+ * alt i is undefined
39
+ * getSlogan->>Math.random: Generate random index
40
+ * Math.random-->>getSlogan: Return random index
41
+ * else i is defined
42
+ * Note over getSlogan: Use provided index
43
+ * end
44
+ * getSlogan->>slogans: Access slogan at index
45
+ * slogans-->>getSlogan: Return slogan
46
+ * alt Error occurs
47
+ * getSlogan->>getSlogan: Throw error
48
+ * end
49
+ * getSlogan-->>Caller: Return slogan
50
+ */
51
+ export declare function getSlogan(i?: number): string;
@@ -0,0 +1,3 @@
1
+ export * from './common';
2
+ export * from './logging';
3
+ export * from './types';