Package Exports
- question-cache
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (question-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
question-cache 
A tiny wrapper around inquirer that makes it easy to create and selectively reuse questions. Useful for project generators like yeoman or generate.
Install
Install with npm
$ npm i question-cache --saveUsage
var Questions = require('question-cache');
// you must pass your own instance of inquirer!
var questions = new Questions({
inquirer: require('inquirer')
});API
Questions
Create an instance of Questions with the given options.
Params
options{Object}: Pass your instance of inquireron theinquireroption.
Example
var inquirer = require('inquirer')
var questions = new Questions({inquirer: inquirer});.set
Store a question object by key.
Params
key{String}: Unique question id.value{Object}: Question object that follows inquirerconventions.
Example
questions.set('name', {
type: 'input',
message: 'Project name?',
default: 'undefined'
});.get
Get a question by key.
Params
key{String}: Unique question id.value{Object}: Question object that follows inquirerconventions.
Example
questions.get('name');
//=> {type: 'input', message: 'What is your name?', default: ''}.ask
Ask a question or array of questions.
Params
key{String}: Unique question id.value{Object}: Question object that follows inquirerconventions.
Example
questions.ask(['name', 'homepage']);
//=> { name: 'foo', homepage: 'https://github/foo' }.prompt
Exposes the prompt method on inquireras a convenience.
Params
question{Object|Array}: Question object or array of question objects.callback{Object}: Callback function.
Example
questions.prompt({
type: 'list',
name: 'chocolate',
message: 'What\'s your favorite chocolate?',
choices: ['Mars', 'Oh Henry', 'Hershey']
}, function(answers) {
//=> {chocolate: 'Hershey'}
});Example
var Questions = require('question-cache');
var inquirer = require('inquirer');
var questions = new Questions({inquirer: inquirer});
questions
.set('first', {
type: 'input',
message: 'What is your first name?',
default: ''
})
.set('last', {
type: 'input',
message: 'What is your last name?',
default: ''
})
.ask(function (err, answers) {
console.log(answers);
//=> { first: 'Jon', last: 'Schlinkert' }
});
/**
* Nested questions
*/
questions.prompt({
type: 'list',
name: 'chocolate',
message: 'What\'s your favorite chocolate?',
choices: ['Mars', 'Oh Henry', 'Hershey']
}, function (answers) {
questions.prompt({
type: 'list',
name: 'beverage',
message: 'And your favorite beverage?',
choices: ['Pepsi', 'Coke', '7up', 'Mountain Dew', 'Red Bull']
}, function (answers) {
console.log(answers);
});
});Screen capture
Other awesome projects
- generate: Project generator, for node.js.
- option-cache: Simple API for managing options in JavaScript applications.
- verb: Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… more
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on July 13, 2015.