Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
question-store
Advanced tools
Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.
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.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm i question-store --save
var Questions = require('question-store');
Create an instance of Questions
with the given options
.
Params
options
{Object}: question store optionsExample
var Questions = new Questions(options);
Cache 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?');
// or
questions.set('drink', {
type: 'input',
message: 'What is your favorite beverage?'
});
// or
questions.set({
name: 'drink'
type: 'input',
message: 'What is your favorite beverage?'
});
Get question name
, or group name
if question is not found. You can also do a direct lookup using quesions.cache['foo']
.
Params
name
{String}returns
{Object}: Returns the question object.Example
var name = questions.get('name');
//=> question object
Returns true if questions.cache
or questions.groups
has question name
.
returns
{String}: The name of the question to checkExample
var name = questions.has('name');
//=> true
Delete the given question or group.
returns
{String}: The name of the question to deleteExample
questions.del('name');
questions.get('name');
//=> undefined
Set the answer for question name
at the current cwd.
Optionally specify a locale to set, otherwise the answer is set for the default locale.
Params
name
{String}locale
{String}returns
{Object}: Returns the answer object.Example
questions.setAnswer('name', 'Jack');
questions.getAnswer('name');
//=> {name: 'Jack'}
// specify a locale
questions.setAnswer('name', 'fr');
questions.getAnswer('name');
//=> {name: 'Jack'}
questions.getAnswer('name', 'fr');
//=> {name: 'Jean'}
Get the answer for question name
at the current cwd.
Optionally specify a locale to get, otherwise the default locale's answer is returend.
Params
name
{String}locale
{String}returns
{Object}: Returns the question object.Example
var name = questions.getAnswer('name');
//=> {name: 'Jon'}
// specify a locale
var name = questions.getAnswer('name', 'fr');
//=> {name: 'Jean'}
Delete the answer for question name
for the current (or given) locale.
Params
name
{String}: Question namelocale
{String}: Optionally pass a localeExample
question.delAnswer(locale);
Add a question that will have its answer stored as a default value.
Params
name
{String}val
{Object}options
{Object}Example
questions.setDefault('author.name', 'What is your name?');
Set the default answer object for question name
for the current locale. Optionally specify a locale to set the default answer for that locale.
Params
name
{String}locale
{String}returns
{Object}: Returns the question object.Example
var name = questions.setDefault('name');
//=> {name: 'Jon'}
// specify a locale
var name = questions.setDefault('name', 'fr');
//=> {name: 'Jean'}
Get the default answer object for question name
for the current locale. Optionally specify a locale to get the default answer for that locale.
Params
name
{String}locale
{String}returns
{Object}: Returns the question object.Example
var name = questions.getDefault('name');
//=> {name: 'Jon'}
// specify a locale
var name = questions.getDefault('name', 'fr');
//=> {name: 'Jean'}
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 localeExample
question.isAnswered(locale);
Set data to be used for answering questions, or as default answers when force
is true.
Params
key
{String|Object}: Property name to set, or object to merge onto questions.data
val
{any}: The value to assign to key
Example
questions.setData('foo', 'bar');
// or
questions.setData({foo: 'bar'});
Return true if property key
has a value on questions.data
.
Params
key
{String}: The property to lookup.returns
{Boolean}Example
questions.hasData('abc');
Get the value of property key
from questions.data
.
Params
key
{String}: The property to get.returns
{any}: Returns the value of property key
Example
questions.setData('foo', 'bar');
questions.getData('foo');
//=> 'bar'
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');
Delete a question.
Params
name
{String}: The question to delete.Example
question.deleteQuestion(name);
Get a group with the given key
. If key
has a dot, only the substring before the dot is used for the lookup.
Params
key
{String}returns
{Object}Example
questions
.set('author.name', 'Author name?')
.set('author.url', 'Author url?')
.set('project.name', 'Project name?')
.set('project.url', 'Project url?')
var group = questions.getGroup('author');
//=> ['author.name', 'author.url']
questions.ask(group, function(err, answers) {
// do stuff with answers
});
Delete answers for all questions for the current (or given) locale.
Params
locale
{String}: Optionally pass a localeExample
question.deleteAll(locale);
Erase all answers for question name
from the file system.
Params
name
{String}: Question nameExample
question.erase(name);
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 functionExample
questions.ask(['name', 'description'], function(err, answers) {
console.log(answers);
});
Get a the index of question name
from the queue.
Params
name
{String}returns
{Object}Example
questions.getIndex('author');
//=> 1
Remove a question from the queue.
Params
items
{Object}: Object of viewsExample
console.log(questions.queue);
//=> ['a', 'b', 'c'];
questions.unqueue('a');
Create new Question
store name
, with the given options
.
Params
name
{String}: The question property name.options
{Object}: Store optionsExample
var question = new Question(name, options);
Set the answer to the question for the current (or given) locale, at the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.setAnswer('foo');
Get the answer for the current (or given) locale for the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.getAnswer(locale);
Delete the answer for the current (or given) locale and the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.delAnswer(locale);
Set the default answer to use for the current (or given) locale, at the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.setDefault('foo');
Get the default answer for the current (or given) locale
Params
locale
{String}: Optionally pass a localeExample
question.getDefault();
Return true if the question has been given a default answer for the current (or given) locale, at the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.hasDefault('es');
Delete the answer store (all answers for the question) from the file system.
Example
question.eraseAnswer();
Return true if the question has been answered for the current locale and the current working directory.
Params
locale
{String}: Optionally pass a localeExample
question.isAnswered(locale);
Return true if the question will be forced (asked even if it already has an answer).
returns
{Boolean}Example
question.options.force = true;
question.isForced();
//=> true
Ask the question.
options.force
is true, the answer will be asked asked even if the answer is already stored.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 functionExample
question.ask({force: true}, function(err, answer) {
console.log(answer);
});
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb on January 14, 2016.
FAQs
Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.
The npm package question-store receives a total of 25,133 weekly downloads. As such, question-store popularity was classified as popular.
We found that question-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.