@marlonconstante/inquirer-recursive
v0.0.17
Published
Recursive prompt for inquirer.js
Downloads
11
Maintainers
Readme
inquirer-recursive
recursive prompt for inquirer
Installation
npm install --save inquirer-recursive
Usage
###Register the prompt
inquirer.registerPrompt('recursive', require('inquirer-recursive'));
inquirer.prompt({
type: 'recursive',
message: message
prompts: prompts
})
Change recursive
to whatever you might prefer.
Options
-message (String) The question that will be ask for interating over prompts default: Would you like to loop ? -prompts (Object) Prompts that will be asked multiple times (Required) see
Example
inquirer.registerPrompt('recursive', require('inquirer-recursive'));
inquirer.prompt([{
type: 'recursive',
message: 'Add a new user ?',
name: 'users',
prompts: [
{
type: 'input',
name: 'name',
message: 'What is user\'s name?',
validate: function (value) {
if ((/.+/).test(value)) { return true; }
return 'name is required';
}
}, {
type: 'input',
name: 'age',
message: 'How old is he?',
validate: function (value) {
var digitsOnly = /\d+/;
if (digitsOnly.test(value)) { return true; }
return 'Invalid age! Must be a number genius!';
}
}
]
}]).then(function(answers) {
console.log(answers.users);
/*
OUTPUT :
[
{
name: 'Brendan Eich',
age: '42',
}, {
name: 'Jordan Walke',
age: '13',
},
...
]
*/
});
Credits
License
MIT