Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

question-store

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

question-store

Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.

  • 0.7.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
increased by10.4%
Maintainers
1
Weekly downloads
 
Created
Source

question-store NPM version Build Status

Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.

TOC

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install question-store --save

Similar to question-cache, but persists answers to disk and supports locales and storing answers based on current working directory.

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);

.set

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

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

.has

Returns true if questions.cache or questions.groups has question name.

  • returns {String}: The name of the question to check

Example

var name = questions.has('name');
//=> true

.del

Delete the given question or group.

  • returns {String}: The name of the question to delete

Example

questions.del('name');
questions.get('name');
//=> undefined

.clear

Delete the given question or group.

  • returns {String}: The name of the question to delete

Example

questions.del('name');
questions.get('name');
//=> undefined

.delQuestion

Delete a question.

Params

  • name {String}: The question to delete.

Example

question.delQuestion(name);

.getGroup

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
});

.clearCache

Clear cached answer data. Note that this will not clear answers that are persisted to the file system, or answers stored on a question. It only clears cached answers on questions.

Example

questions.clearCache();

.deleteAll

Delete answers for all questions for the current (or given) locale.

Params

  • locale {String}: Optionally pass a locale

Example

question.deleteAll(locale);

.erase

Erase all answers for question name from the file system.

Params

  • name {String}: Question name

Example

question.erase(name);

.ask

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 function
  • callback {Function}: callback function

Example

questions.ask(['name', 'description'], function(err, answers) {
  console.log(answers);
});

.getIndex

Get a the index of question name from the queue.

Params

  • name {String}
  • returns {Object}

Example

questions.getIndex('author');
//=> 1

.unqueue

Remove a question from the queue.

Params

  • items {Object}: Object of views

Example

console.log(questions.queue);
//=> ['a', 'b', 'c'];
questions.unqueue('a');

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);

.set

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.set('foo', 'bar');

.get

Get key from the question.

Params

  • key {String}

Example

question.set('foo', 'bar');
question.get('foo');
//=> 'bar'

.setAnswer

Return the answer for the current locale and current working directory.

Params

  • locale {String}: Optionally pass a locale

Example

question.getAnswer(locale);

.getAnswer

Return the answer for the current locale and current working directory.

Params

  • locale {String}: Optionally pass a locale

Example

question.getAnswer(locale);

.hasAnswer

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.hasAnswer(locale);

.setDefault

Return the answer for the current locale and current working directory.

Params

  • locale {String}: Optionally pass a locale

Example

question.setDefault('Jon', 'en');
question.setDefault('Jean', 'fr');

.erase

Erase the answer for a question.

  • returns {Boolean}

Example

question.erase();
question.hasAnswer();
//=> false

.force

Force the question to be asked.

  • returns {Boolean}

Example

question.options.force = true;
question.isForced();
//=> true

.isForced

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

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 function
  • callback {Function}: callback function

Example

question.ask({force: true}, function(err, answer) {
  console.log(answer);
});

.setAnswer

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'}

.getAnswer

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'}

.hasAnswer

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.hasAnswer('name', 'fr');
//=> true

.setDefault

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.setDefault('name', 'Jack');
questions.getDefault('name');
//=> {name: 'Jack'}

// specify a locale
questions.setDefault('name', 'fr');

questions.getDefault('name');
//=> {name: 'Jack'}
questions.getDefault('name', 'fr');
//=> {name: 'Jean'}

.getDefault

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.setDefault('name', 'Brian');
var name = questions.setDefault('name', 'Jean', 'fr');

var name = questions.getDefault('name');
//=> {name: 'Brian'}

// specify a locale
var name = questions.getDefault('name', 'fr');
//=> {name: 'Jean'}

.hasDefault

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.setDefault('name', 'Brian', 'fr');
var name = questions.hasDefault('name', 'fr');
//=> true
var name = questions.hasDefault('name', 'en');
//=> false

.setData

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'});

.hasData

Return true if property key has a value on questions.data.

Params

  • key {String}: The property to lookup.
  • returns {Boolean}

Example

questions.hasData('abc');

.getData

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'
  • 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

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016 Jon Schlinkert Released under the MIT license.


This file was generated by verb, v0.9.0, on February 23, 2016.

Keywords

FAQs

Package last updated on 23 Feb 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc