1.1.1 • Published 6 years ago

node-console-input v1.1.1

Weekly downloads
3
License
ISC
Repository
-
Last release
6 years ago

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.