1.0.11 • Published 9 years ago

prompt-console v1.0.11

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

prompt-console

Take input from command prompt in nodeJS applications.

Example Usage

var prompt = require('prompt-console');

A Simple example to show how to validate and take nested inputs.

//syntax: prompt.ask(array of objects(with question details), success callback function);

prompt.ask(
    [{   
    question: 'What is your name? ',
        validator: 'notNULL',
        color: 'green',
        name: 'name'
    },{   
        question: 'What is your age? ',
        validator: /\d/, //can be any regex expression or function
        color: 'yellow',
        name: 'age'
    },{   
        question: 'Which year were you born in? ',
        type: 'password', //or type='hidden'
        validator: function(year, answers){
			try{
                var date1 = new Date();
                date1.setYear(year);
                var date2 = new Date();
                var timeDiff = Math.abs(date2.getTime() - date1.getTime());
                var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
                var ret = Math.floor(diffDays / 365) == answers.age;
                if(!ret) console.log("Wrong birth year, you would be of " + Math.floor(diffDays / 365) + " years if born in " + year);
                return ret;
			}catch(e){
                return false;
			}

		},
        color: 'cyan',
        name: 'year'
    }], function(response){
        console.log('That is the right year of birth ' + response.name + ', have a good day!');
    }
);

// the validator can be a pattern or a function(returning true/false)
1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago