UNPKG

@augment-vir/node

Version:

A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.

51 lines (50 loc) 2.2 kB
import { type AnyDuration } from '@date-vir/duration'; /** Can't test requiring user input. */ /** * Options for {@link askQuestion}. * * @category Node : Terminal : Util * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export type AskQuestionOptions = { timeout: AnyDuration; hideUserInput: boolean; }; /** * Asks the user a question in their terminal and then waits for them to type something in response. * The response is accepted once the user inputs a new line. * * @category Node : Terminal * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) * @see * - {@link askQuestionUntilConditionMet}: ask a question on loop until the user provides a valid response. */ export declare function askQuestion(questionToAsk: string, { hideUserInput, timeout, }?: Partial<AskQuestionOptions>): Promise<string>; /** * Options for {@link askQuestionUntilConditionMet}. * * @category Node : Terminal : Util * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export type QuestionUntilConditionMetOptions = { questionToAsk: string; /** Callback to call with the user's response to verify if their response is valid. */ verifyResponseCallback: (response: string) => boolean | Promise<boolean>; invalidInputMessage: string; tryCountMax?: number; } & Partial<AskQuestionOptions>; /** * Asks the user a question in their terminal and then waits for them to type something in response. * The response is submitted once the user inputs a new line. If the response fails validation, the * question is presented again. * * @category Node : Terminal * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) * @see * - {@link askQuestion}: ask a question and accept any response. */ export declare function askQuestionUntilConditionMet({ questionToAsk, verifyResponseCallback, invalidInputMessage, tryCountMax, ...options }: QuestionUntilConditionMetOptions): Promise<string>;