Function question

  • Interactive question.

    Remarks

    Small abstraction layer on top the question method of Node's readline module.

    Example

    import { createInterface } from "node:readline/promises";

    const exampleQuestion = question(createInterface({
    input: process.stdin,
    output: process.stdout,
    }));

    exampleQuestion({
    format: value => parseInt(value, 18),
    query: "How old are you?",
    validate: value => (value < 18 ? "You must be at least 18 years old." : ""),
    }).then(console.log).catch(console.error);

    See

    Parameters

    • questionObject: QuestionObject

      Object with a question function that returns a promise.

    Returns (<FormattedValue>(options) => Promise<FormattedValue>)

    Curried function with questionObject set in context.

      • <FormattedValue>(options): Promise<FormattedValue>
      • Interactive question with questionObject set in context.

        See

        question

        Type Parameters

        • FormattedValue = string

          Result of the value after formatting.

        Parameters

        • options: QuestionOptions<FormattedValue>

          Options object for the question.

        Returns Promise<FormattedValue>

        Promise with the question's answer.