UNPKG

easy-cli-framework

Version:

A framework for building CLI applications that are robust and easy to maintain. Supports theming, configuration files, interactive prompts, and more.

63 lines (62 loc) 2.08 kB
import { DisplayOptions, EasyCLITheme } from '../themes'; /** * Options for the promptNumber function * * @interface PromptNumberOptions * @type {object} * * @property {number | null} [value=null] The default value to use * @property {(input: number) => boolean} [validator=() => true] A function to validate the input * @property {string} [validationErrorMessage='Invalid input'] The error message to display if the input is invalid * @property {EasyCLITheme} [theme=null] The theme to use * @property {DisplayOptions} [promptTheme='default'] The theme to use for the prompt * * @example * ```typescript * { * value: 10, * validator: input => input >= 0, * validationErrorMessage: 'Number must be greater than or equal to 0', * theme: new EasyCLITheme(), * promptTheme: 'info', * } * ``` */ export type PromptNumberOptions = { value?: number | null; validator?: (input: number) => boolean; validationErrorMessage?: string; theme?: null | EasyCLITheme; promptTheme?: DisplayOptions; }; /** * Prompts the user to enter a number. * * @param {string} prompt The prompt to display to the user * @param {PromptNumberOptions} options The options for the prompt * * @returns {Promise<number>} The number the user entered * * @example * ```typescript * // Prompt the user to enter a number * const number = await promptNumber('Enter a number'); * console.log(number); * * // Prompt the user to enter a number between 1 and 10 * const number = await promptNumber('Enter a number between 1 and 10', { * validator: (input) => input >= 1 && input <= 10, * validationErrorMessage: 'Number must be between 1 and 10', * }); * console.log(number); * * // Prompt the user to enter a number using a custom theme * const number = await promptNumber('Enter a number', { * theme: new EasyCLITheme(), * promptTheme: 'info', * }); * console.log(number); * ``` * */ export declare const promptNumber: (prompt: string, { value, validator, validationErrorMessage, theme, promptTheme, }?: PromptNumberOptions) => Promise<any>;