Skip to content

Commit 5f75372

Browse files
author
Vincent Tan
committed
Improve comments for promptUtils functions
Signed-off-by: Vincent Tan <[email protected]>
1 parent 4550c84 commit 5f75372

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/helpers/promptUtils.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { Question, Questions, ux } from '@cto.ai/sdk'
22

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+
*/
610
export const validatedPrompt = async (
711
prompt: Question | Questions,
812
validate: (response: any) => boolean,
@@ -23,13 +27,13 @@ export const validatedPrompt = async (
2327
return response
2428
}
2529

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 (
3337
prompt: Question,
3438
choices: { name: string; value: any }[],
3539
) => {

0 commit comments

Comments
 (0)