Skip to content

Commit

Permalink
Merge pull request #195 from arlando/feature-when-example
Browse files Browse the repository at this point in the history
Added an example using when.
  • Loading branch information
SBoudrias committed Dec 9, 2014
2 parents 52e58ce + 0e3fe96 commit 8fafcae
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/when.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* When example
*/

"use strict";
var inquirer = require("../lib/inquirer");

var questions = [
{
type: "confirm",
name: "bacon",
message: "Do you like bacon?"
},
{
type: "input",
name: "favorite",
message: "Bacon lover, what is your favorite type of bacon?",
when: function ( answers ) {
return answers.bacon;
}
},
{
type: "confirm",
name: "pizza",
message: "Ok... Do you like pizza?",
when: function (answers) {
return !likesFood( "bacon" )(answers);
}
},
{
type: "input",
name: "favorite",
message: "Whew! What is your favorite type of pizza?",
when: likesFood( "pizza" )
}
];

function likesFood ( aFood ) {
return function ( answers ) {
return answers[ aFood ];
}
}

inquirer.prompt(questions, function (answers) {
console.log( JSON.stringify(answers, null, " ") );
});

0 comments on commit 8fafcae

Please sign in to comment.