Easily prompt the user with a series of questions.
Easily prompt the user with a series of questions.
I wanted a package that I could easily specify an array of words and then have it ask a series of questions. Now you can be a bit more productive.
npm install readline-prompter
There is an error with the test on Node v0.6. Not sure what’s causing it.
var rlp = require('readline-prompter');
var tokens = ['first name', 'last name', 'cats name'];
var def = {'name': {
defaultResponse: 'JP',
display: 'JP Smith'
}};
var skip = {'cats name': 'petey'};
rlp(tokens, def, skip).end(function(results) {
console.log(results);
});
The default for ‘name’ is “JP” in this case (though it displays as ‘JP Smith’ to the user). ‘cats name’ gets skipped. You would have to type in something for ‘last name’, it won’t let you skip it.
Console:
name: (JP Smith)
last name:
Output:
{
"name": "JP",
"last name": "Richardson",
"cats name": "petey"
}
node-readline-prompter was written by JP Richardson. You should follow him on Twitter @jprichardson. Also read his coding blog Procbits. If you write software with others, you should checkout Gitpilot to make collaboration with Git simple.
(MIT License)
Copyright 2012, JP Richardson jprichardson@gmail.com