1
1
import { Question , Questions , ux } from '@cto.ai/sdk'
2
2
3
- //This re-prompts user until their answer passes validation
4
- //validate takes in the return value of ux.prompt, and forces re-prompt if it returns false
5
- //errorMessage is displayed to user when validation fails
3
+ /**
4
+ * Re-prompt until the answer passes validation
5
+ * @param {Question | Questions } prompt
6
+ * @param {(response: any) => boolean } validate takes in the return value of ux.prompt, and forces re-prompt if it returns false
7
+ * @param {string } errorMessage is displayed to user when validation fails
8
+ * @returns {string } validated response
9
+ */
6
10
export const validatedPrompt = async (
7
11
prompt : Question | Questions ,
8
12
validate : ( response : any ) => boolean ,
@@ -23,13 +27,13 @@ export const validatedPrompt = async (
23
27
return response
24
28
}
25
29
26
- //this replicates the SDK 1.x functionality,
27
- //where you can have a separate display name and actual value returned
28
- // prompt should be a ListQuestion, AutoCompleteQuestion, CheckboxQuestion
29
- // name must be unique, as it is used as a key
30
- //having duplicate names causes undefined behaviour (probably just returns one of the matching at random)
31
- //prompt.choices will be overwritten, so feel free to set it to anything
32
- export const keyValPrompt : ( prompt : Question , choices : { name : string ; value : any ; } [ ] ) => Promise < { [ x : string ] : any ; } > = async (
30
+ /**
31
+ * Shows prompt(s) with choices.name as options, but returns choices. value
32
+ * @param { Question } prompt whose choices will be overwritten by this function
33
+ * @param { { name: string; value: any;}[] } choices consists of display names offered to users, and value which is actually returned when selected
34
+ * @returns { any } the corresponding values of any choices selected
35
+ */
36
+ export const keyValPrompt : ( prompt : Question , choices : { name : string ; value : any ; } [ ] ) => Promise < { [ x : string ] : any ; } > = async (
33
37
prompt : Question ,
34
38
choices : { name : string ; value : any } [ ] ,
35
39
) => {
0 commit comments