Namespace: Input

Input

Functions to get input synchronously from the user

Methods

(static) input(prompt, limitopt, limitMessageopt) → {String}

Displays a prompt and gets input from the user

Parameters:
Name Type Attributes Default Description
prompt String
limit String | Number | RegExp | function | Array <optional>
null

Limits valid input to specified choices.

limitMessage String <optional>
null

Message to display when user enters invalid input

Since:
  • 0.1.0
Returns:
Type
String
Example
input("Tell me something good: ") // no limit on input
input("Say 'potato': ", "potato") // can only input "potato"
input("Give me a word ending in 's': ", /.*s$/) // can only input words ending in "s"
input("How's the weather? ", ["rainy", "sunny", "cloudy", "snowing"]) // limits choices to those 4 words
input("Enter a valid IPv4 address: ", function(input) {
 return require("net").isIp(input);
}) // only allows you to enter a value for which the function returns true
input("Say 'potato': ", "potato", "You can only say 'potato'!") // example of limitMessage

(static) inputChoice(choices, prompt) → {Number}

Displays a prompt for the user to choose one from a list of choices

Parameters:
Name Type Description
choices Array.<Any>

The list of choices

prompt String
Since:
  • 0.1.0
Returns:

The array index of the user's choice, or -1 if they choose cancel

Type
Number

(static) inputHidden(prompt) → {String}

Displays a prompt and gets input where the console output is replaced by '*'

Parameters:
Name Type Description
prompt String
Since:
  • 0.1.0
Returns:
Type
String

(static) inputKey(prompt, limitopt, limitMessageopt) → {String}

Gets a single-key input from the user

Parameters:
Name Type Attributes Default Description
prompt String
limit String | Number | Array <optional>
null

Limit which keys are accepted as input

limitMessage String <optional>
null

Message to display when user enters invalid input

Since:
  • 0.1.0
Returns:
Type
String
Example
inputKey("Press any key"); // no limit
inputKey("Press a, b, or c", "abc") // limits valid inputs to a, b, or c
inputKey("Press a, b, or c", ["a", "b", "c"]) // limits valid inputs to a, b, or c

(static) inputWithDefault(prompt, defaultInput) → {String}

Prompts the user for input and returns a default value if there is no input

Parameters:
Name Type Description
prompt String
defaultInput String

Returns this if user inputs no value

Since:
  • 0.1.0
Returns:
Type
String
Example
inputWithDefault("How are you doing? ", "meh...") // returns "meh..." if user enters no input

(static) inputYOrN(prompt) → {Boolean}

Displays a prompt and gets a Y/N response from the user

Parameters:
Name Type Description
prompt String
Since:
  • 0.1.0
Returns:

true for "Y", else false

Type
Boolean

(static) pauseForInput(prompt, limitopt, limitMessageopt) → {undefined}

Pauses script execution to wait for the user to press a key

Parameters:
Name Type Attributes Default Description
prompt String
limit String | Number | RegExp | function | Array <optional>
null

Limits valid input to specified choices.

limitMessage String <optional>
null

Message to display when user enters invalid input

Since:
  • 0.1.0
Returns:
Type
undefined