IO

IO

Utilities for clean log output and user input.

Constructor

new IO()

Source:

Methods

bell() → {Promise}

Source:

Rings an auditory bell when prompting for input.

Returns:

resolves when the sound is finished playing, or immediately if bell is disabled.

Type
Promise

(private) formatYesNo(defaultVal) → {Object}

Source:

Provides the format for the "Y/N" prompt.

Parameters:
Name Type Description
defaultVal String

the default value for the question.

Returns:

{ y, n } containing formatted strings for the Y and N parts of the default input.

Type
Object

status(msg) → {void}

Source:

Provides a section header to mark a section of script running.

Parameters:
Name Type Description
msg String

the message to print.

Returns:
Type
void

yesNo(question, consoleDefault, ciDefault) → {Promise.<Boolean>}

Source:

Queries the user for a "yes/no" question. If in CI, uses a default, and creates fake console output to simulate asking the question to the user and getting a response, to allow the user to follow along.

Example

Basic Usage

const io = new IO();
io
   .yesNo("Use current directory, instead of '/var/my-app/'?", "Y", "N")
   .then(answer => console.log(answer ? "Using current directory." : "Using '/var/my-app/'."));
Parameters:
Name Type Description
question String

the text of the question to ask the user.

consoleDefault String

the default input if the user doesn't provide input. Use "Y" or "N".

ciDefault String

the default input to use in CI. Use "Y" or "N".

Returns:

true if the user answered "yes", false if the user answered "no".

Type
Promise.<Boolean>