node-console-input
v1.1.1
Published
A basic console input library
Downloads
16
Readme
Usage
Accepting input
Code:
const conif = require('node-console-input');
var name = conif.getConsoleInput("Name: ", false);
console.log("Hello, " + name + "\n");
var age = conif.getConsoleIntegerInput("Age: ");
console.log("You are " + name + " years old\n");
var height = conif.getConsoleFloatInput("Height: ");
console.log("You are " + height + " metres tall");
Output:
Name: myName
Hello, myName
Age: 27
You are 27 years old
Height: 2.25
You are 2.25 metres tall
Functions
getConsoleInput (promptText[, acceptBlank])
acceptBlank
defaults to false
.
Will display prompText
then will wait until user has inputed something, if acceptBlank
is true
will accept nothing as an input. When invalid input is detected will repeat prompt.
getConsoleIntegerInput (promptText)
Will display prompText
then will wait until user has inputed something. When invalid input is detected will repeat prompt. Will truncate floats to integers.
getConsoleFloatInput (promptText)
Will display prompText
then will wait until user has inputed something. When invalid input is detected will repeat prompt.