# base-questions

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

Latest version **0.9.1** (published 2016-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install base-questions
pnpm add base-questions
yarn add base-questions
bun add base-questions
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.1 |
| Published | 2016-12-01 |
| First published | 2015-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 12 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | api, app, application, ask, base, baseplugin, building-blocks, choice, choices, cli, command, command-line, console, create, framework, line, plugin, plugins, prompt, question, questions, terminal, tool, toolkit, tools |

## Links

- npm: https://www.npmjs.com/package/base-questions
- Repository: https://github.com/node-base/base-questions
- Issues: https://github.com/node-base/base-questions/issues
- npm.io page: https://npm.io/package/base-questions

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [isobject](https://npm.io/package/isobject.md) ^2.1.0
- [get-value](https://npm.io/package/get-value.md) ^2.0.6
- [set-value](https://npm.io/package/set-value.md) ^0.4.0
- [base-store](https://npm.io/package/base-store.md) ^0.4.4
- [clone-deep](https://npm.io/package/clone-deep.md) ^0.2.4
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^2.0.1
- [mixin-deep](https://npm.io/package/mixin-deep.md) ^1.1.3
- [is-valid-app](https://npm.io/package/is-valid-app.md) ^0.2.1
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1
- [question-store](https://npm.io/package/question-store.md) ^0.13.0
- [define-property](https://npm.io/package/define-property.md) ^0.2.5

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.9.1 (latest) — 2016-12-01
- 0.9.0 — 2016-10-01
- 0.8.1 — 2016-08-17
- 0.8.0 — 2016-08-17
- 0.7.4 — 2016-07-29
- 0.7.3 — 2016-07-17
- 0.7.2 — 2016-07-17
- 0.7.1 — 2016-07-11
- 0.7.0 — 2016-07-11
- 0.6.6 — 2016-05-24
- 0.6.5 — 2016-05-21
- 0.6.4 — 2016-05-19
- 0.6.3 — 2016-05-15
- 0.6.2 — 2016-05-14
- 0.6.1 — 2016-05-12
- … 22 more at https://npm.io/package/base-questions/versions

## README

# base-questions [![NPM version](https://img.shields.io/npm/v/base-questions.svg?style=flat)](https://www.npmjs.com/package/base-questions) [![NPM downloads](https://img.shields.io/npm/dm/base-questions.svg?style=flat)](https://npmjs.org/package/base-questions) [![Build Status](https://img.shields.io/travis/node-base/base-questions.svg?style=flat)](https://travis-ci.org/node-base/base-questions)

> 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](https://github.com/jonschlinkert/data-store).

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [About](#about)
  * [Related projects](#related-projects)
  * [Contributing](#contributing)
  * [Contributors](#contributors)
  * [Building docs](#building-docs)
  * [Running tests](#running-tests)
  * [Author](#author)
  * [License](#license)

_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save base-questions
```

## Usage

Try running the [actual examples](./example.js) if it helps to see the following example in action.

```js
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

### [.confirm](index.js#L108)

Create a `confirm` question.

**Params**

* `name` **{String}**: Question name
* `msg` **{String}**: Question message
* `queue` **{String|Array}**: Name or array of question names.
* `options` **{Object|Function}**: Question options or callback function
* `callback` **{Function}**: callback function

**Example**

```js
app.confirm('file', 'Want to generate a file?');

// equivalent to
app.question({
  name: 'file',
  message: 'Want to generate a file?',
  type: 'confirm'
});
```

### [.choices](index.js#L142)

Create a "choices" question from an array.

**Params**

* `name` **{String}**: Question name
* `msg` **{String}**: Question message
* `choices` **{Array}**: Choice items
* `queue` **{String|Array}**: Name or array of question names.
* `options` **{Object|Function}**: Question options or callback function
* `callback` **{Function}**: callback function

**Example**

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

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

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

### [.question](index.js#L175)

Add a question to be asked by the `.ask` method.

**Params**

* `name` **{String}**: Question name
* `msg` **{String}**: Question message
* `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**

```js
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](index.js#L200)

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**

```js
// 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);
});
```

## About

### Related projects

* [answer-store](https://www.npmjs.com/package/answer-store): Store answers to user prompts, based on locale and/or current working directory. | [homepage](https://github.com/jonschlinkert/answer-store "Store answers to user prompts, based on locale and/or current working directory.")
* [common-questions](https://www.npmjs.com/package/common-questions): An object of questions commonly used by project generators or when initializing projects. Questions can… [more](https://github.com/generate/common-questions) | [homepage](https://github.com/generate/common-questions "An object of questions commonly used by project generators or when initializing projects. Questions can be overridden, updated or extended.")
* [question-store](https://www.npmjs.com/package/question-store): Ask questions, persist the answers. Basic support for i18n and storing answers based on current… [more](https://github.com/jonschlinkert/question-store) | [homepage](https://github.com/jonschlinkert/question-store "Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.")
* [to-choices](https://www.npmjs.com/package/to-choices): Easily create a normalized inquirer choices question. Supports all of the `choices` question types: checkbox… [more](https://github.com/generate/to-choices) | [homepage](https://github.com/generate/to-choices "Easily create a normalized inquirer choices question. Supports all of the `choices` question types: checkbox, list, rawlist, expand")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Building docs

_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_

To generate the readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install -g verb verb-generate-readme && verb
```

### Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

### License

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/node-base/base-questions/blob/master/LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on October 01, 2016._

---
_Source: https://npm.io/package/base-questions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
