question-store
Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.
Similar to question-cache, but persists answers to disk and supports locales and storing answers based on current working directory.
Install
Install with npm
$ npm i question-store --save
Usage
var Questions = require('question-store');
API
Questions
Create an instance of Questions
with the given options
.
Params
options
{Object}: question store options
Example
var Questions = new Questions(options);
Queue up a question to be asked at a later point. Creates an instance of Question, so any Question
options or settings may be used.
Params
value
{Object|String}: Question object, message (string), or options object.locale
{String}: Optionally pass the locale to use, otherwise the default locale is used.
Example
questions.set('drink', 'What is your favorite beverage?');
questions.set('drink', {
type: 'input',
message: 'What is your favorite beverage?'
});
questions.set({
name: 'drink'
type: 'input',
message: 'What is your favorite beverage?'
});
Get the question
instance stored for the given name
. This is the entire Question
object, with all answers for all locales and directories.
Params
name
{String}returns
{Object}: Returns the question instance.
Example
var name = questions.question('name');
Get the answer object for question name
, for the current locale and cwd.
Params
name
{String}locale
{String}returns
{Object}: Returns the question object.
Example
var name = questions.get('name');
var name = questions.get('name', 'fr');
Return true if question name
has been answered for the current locale and the current working directory.
Params
name
{String}: Question namelocale
{String}: Optionally pass a locale
Example
question.isAnswered(locale);
Delete the answer for question name
for the current (or given) locale.
Params
name
{String}: Question namelocale
{String}: Optionally pass a locale
Example
question.del(locale);
Get the answer value for question name
, for the current locale and cwd. Similar to questions.get
, but only returns the answer value instead of the entire object.
Params
name
{String}locale
{String}returns
{Object}: Returns the question object.
Example
var name = questions.answer('name');
var name = questions.answer('name', 'fr');
Ask one or more questions, with the given options
and callback.
Params
queue
{String|Array}: Name or array of question names.options
{Object|Function}: Question options or callback functioncallback
{Function}: callback function
Example
questions.ask(['name', 'description'], function(err, answers) {
console.log(answers);
});
Question
Create new Question
store name
, with the given options
.
Params
name
{String}: The question property name.options
{Object}: Store options
Example
var question = new Question(name, options);
Update the answer to the question for the current (or given) locale, at the current working directory.
Params
locale
{String}: Optionally pass a locale
Example
question.set('foo');
Get the answer for the current (or given) locale for the current working directory.
Params
locale
{String}: Optionally pass a locale
Example
question.get(locale);
Return true if the question has been answered for the current locale and the current working directory.
Params
locale
{String}: Optionally pass a locale
Example
question.isAnswered(locale);
Ask the question.
- If an answer has already been stored for the current locale and cwd it will be returned directly without asking the question.
- If
options.force
is true, the answer will be asked asked even if the answer is already stored. - If
options.save
is false, the answer will not be persisted to the file system, and the question will be re-asked each time .ask()
is called (which means it's also not necessary to define force
when save
is false).
Params
options
{Object|Function}: Question options or callback functioncallback
{Function}: callback function
Example
question.ask({force: true}, function(err, answer) {
console.log(answer);
});
Delete the answer for the current (or given) locale.
Params
locale
{String}: Optionally pass a locale
Example
question.del(locale);
Persist the answer for the current locale and cwd to disk.
Example
question.save();
Related projects
- answer-store: Store answers to user prompts, based on locale and/or current working directory. | homepage
- inquirer: A collection of common interactive command line user interfaces. | homepage
- question-cache: A wrapper around inquirer that makes it easy to create and selectively reuse questions. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
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 November 24, 2015.