This repository has been archived, use Enquirer instead.
Installations
npm install prompt-question
Releases
Unable to fetch releases
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=4.0.0
Typescript Support
No
Node Version
8.4.0
NPM Version
5.3.0
Statistics
5 Stars
93 Commits
1 Forks
4 Watching
1 Branches
5 Contributors
Updated on 14 Dec 2018
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
21,855,581
Last day
-10.8%
8,373
Compared to previous day
Last week
-0%
53,882
Compared to previous week
Last month
12.7%
228,879
Compared to previous month
Last year
-32.1%
2,518,655
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
prompt-question
Question object, used by Enquirer and prompt plugins.
Install
Install with npm:
1$ npm install --save prompt-question
Usage
The main export is a constructor function that is used to create new Question
objects, which are used in prompts by [base-prompt][].
1var Question = require('prompt-question'); 2var question = new Question('color', 'What is favorite color?');
Examples
Any of the following signatures may be used:
1var question = new Question('color'); // sets message as the same value as `name`
2var question = new Question('color', 'What is favorite color?');
3var question = new Question('color', {message: 'What is favorite color?'});
4var question = new Question({name: 'color', message: 'What is favorite color?'});
5var question = new Question({name: 'color'});
API
Question
Create a new question with the given name
, message
and options
.
Params
name
{String|Object}: Question name or options.message
{String|Object}: Question message or options.options
{String|Object}: Question options.
Example
1var question = new Question('first', 'What is your first name?'); 2console.log(question); 3// { 4// type: 'input', 5// name: 'color', 6// message: 'What is your favorite color?' 7// }
.clone
Clone the question instance.
returns
{Object}: Returns the cloned question
Example
1var clonedQuestion = question.clone();
.addChoices
Add formatted choice objects to the question.choices
array. See prompt-choices for more details.
Params
choices
{String|Array}: One or more choices to add.returns
{Object}: Returns the question instance for chaining
Example
1question.addChoices(['foo', 'bar', 'baz']);
.addChoice
Add a choice to question.choices
array. See prompt-choices for more details.
Params
choice
{String|Object}returns
{Object}: Returns the question instance for chaining
Example
1question.addChoice('foo');
.getDefault
Returns the given val
or question.default
if val
is undefined or null.
Params
val
{any}returns
{any}
Example
1var question = new Question({ 2 name: 'first', 3 message: 'First name'?, 4 default: 'Bob' 5}); 6 7console.log(question.getAnswer()); 8//=> 'Bob' 9console.log(question.getAnswer('Joe')); 10//=> 'Joe' 11console.log(question.getAnswer(false)); 12//=> false 13console.log(question.getAnswer(0)); 14//=> 0
.getChoice
Get the given choice from questions.choices
.
Params
val
{any}returns
{any}
Example
1var Question = require('prompt-question'); 2var question = new Question('color', 'What is your favorite color?', { 3 choices: ['red', 'blue', 'yellow'] 4}); 5console.log(question.getChoice('red')); 6//=> Choice { name: 'red', short: 'red', value: 'red', checked: false }
.separator
Create a separator using choices-separator.
.hasDefault
Getter that returns true if a default
value has been defined.
returns
{Boolean}: True if a default value is defined.
.checkbox
Getter/setter for the checkbox symbols to use.
returns
{Object}: Checkbox object with.on
,.off
and.disabled
properties.
Example
1var question = new Question({ 2 name: 'foo', 3 checkbox: {off: '[ ]', on: '[x]', disabled: 'X'} 4}); 5// or 6question.checkbox = {off: '[ ]', on: '[x]', disabled: 'X'};
.choices
Getter/setter for getting and setting choices (if applicable).
returns
{Object}: Returns an instance of prompt-choices
Example
1var question = new Question(); 2question.choices = ['a', 'b', 'c'];
.Question.isQuestion
Static method that returns true if question
is a valid question object.
Params
question
{Object}returns
{Boolean}
Example
1console.log(Question.isQuestion('foo'));
2//=> false
3console.log(Question.isQuestion(new Question('What is your name?')));
4//=> true
.Question.choices
Static method for creating a new Choices
object. See prompt-choices for more details.
Params
choices
{Array}: Array of choicesreturns
{Object}: Returns an intance of Choices.
Example
1var choices = new Question.Choices(['foo', 'bar', 'baz']);
.Question.Separator
Static method for creating a new Separator
object. See choices-separator for more details.
Params
separator
{String}: Optionally pass a string to use as the separator.returns
{Object}: Returns a separator object.
Example
1new Question.Separator();
Release history
v5.0.0
- Support
.choices
as a function
v4.0.0
- bumps prompt-choices
v3.0.0
- bumps prompt-choices
v2.0.0
- bumps prompt-choices. A major bump was warranted due to potentially breaking changes in prompt-choices. Please see that library for more details.
About
Related projects
- choices-separator: Separator for choices arrays in prompts. Based on the Separator from inquirer. | homepage
- enquirer: Intuitive, plugin-based prompt system for node.js. | homepage
- prompt-choices: Create an array of multiple choice objects for use in prompts. | homepage
- readline-utils: Readline utils, for moving the cursor, clearing lines, creating a readline interface, and more. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 08, 2017.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
53 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-8w4h-3cm3-2pm2
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr
- Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-3mpr-hq3p-49h9
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-36m4-6v6m-4vpr
- Warn: Project is vulnerable to: GHSA-q22g-8fr4-qpj4
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
- Warn: Project is vulnerable to: GHSA-v2p6-4mp7-3r9v
Score
1.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More