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

base-questions

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-questions

Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.

  • 0.5.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
decreased by-3.44%
Maintainers
1
Weekly downloads
 
Created
Source

base-questions NPM version Build Status

Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.

You might also be interested in data-store.

TOC

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install base-questions --save

Usage

Try running the actual examples if it helps to see the following example in action.

var questions = require('base-questions');
var assemble = require('assemble-core');
var store = require('base-store');
var argv = require('base-argv');

var app = assemble();
app.use(store());
app.use(argv());

var argv = app.argv(process.argv.slice(2));
app.use(questions(app, argv.options));

app.task('ask', function (cb) {
  app.ask(function (err, answers) {
    if (err) return cb(err);
    console.log(answers);
    cb();
  });
});

app.task('a', function (cb) {
  console.log('task > a!');
  cb();
});

app.task('b', function (cb) {
  console.log('task > b!');
  cb();
});

app.task('c', function (cb) {
  console.log('task > c!');
  cb();
});

app.task('choices', function (cb) {
  app.choices('run', ['a', 'b', 'c'], function (err, answers) {
    if (err) return cb(err);
    if (!answers.run.length) return cb();
    app.build(answers.run, cb);
  });
});

app.build('choices', function(err) {
  if (err) return console.log(err);
  console.log('done!');
});

API

.choices

Create a "choices" question from an array.

Params

  • queue {String|Array}: Name or array of question names.
  • options {Object|Function}: Question options or callback function
  • callback {Function}: callback function

Example

app.choices('Favorite color?', ['blue', 'orange', 'green']);

// or
app.choices('foo', {
  message: 'Favorite color?',
  choices: ['blue', 'orange', 'green']
});

.question

Add a question to be asked at a later point.

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.
  • returns {Object}: Returns the this.questions object, for chaining

Example

app.question('beverage', 'What is your favorite beverage?');

// or
app.question('beverage', {
  type: 'input',
  message: 'What is your favorite beverage?'
});

// or
app.question({
  name: 'beverage'
  type: 'input',
  message: 'What is your favorite beverage?'
});

.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

// ask all questions
app.ask(function(err, answers) {
  console.log(answers);
});

// ask the specified questions
app.ask(['name', 'description'], function(err, answers) {
  console.log(answers);
});
  • answer-store: Store answers to user prompts, based on locale and/or current working directory. | homepage
  • common-questions: An object of questions commonly used by project generators or when initializing projects. Questions can… more | homepage
  • question-store: Ask questions, persist the answers. Basic support for i18n and storing answers based on current… more | homepage
  • to-choices: Easily create a normalized inquirer choices question. Supports all of the choices question types: checkbox,… more | 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 March 03, 2016.

Keywords

FAQs

Package last updated on 04 Mar 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