Gathering detailed insights and metrics for prompt-question
Gathering detailed insights and metrics for prompt-question
Gathering detailed insights and metrics for prompt-question
Gathering detailed insights and metrics for prompt-question
This repository has been archived, use Enquirer instead.
npm install prompt-question
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5 Stars
93 Commits
1 Forks
4 Watching
1 Branches
5 Contributors
Updated on 14 Dec 2018
JavaScript (100%)
Cumulative downloads
Total Downloads
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
Question object, used by Enquirer and prompt plugins.
Install with npm:
1$ npm install --save prompt-question
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'});
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 the question instance.
returns
{Object}: Returns the cloned questionExample
1var clonedQuestion = question.clone();
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 chainingExample
1question.addChoices(['foo', 'bar', 'baz']);
Add a choice to question.choices
array. See prompt-choices for more details.
Params
choice
{String|Object}returns
{Object}: Returns the question instance for chainingExample
1question.addChoice('foo');
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
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 }
Create a separator using choices-separator.
Getter that returns true if a default
value has been defined.
returns
{Boolean}: True if a default value is defined.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'};
Getter/setter for getting and setting choices (if applicable).
returns
{Object}: Returns an instance of prompt-choicesExample
1var question = new Question(); 2question.choices = ['a', 'b', 'c'];
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
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']);
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();
.choices
as a functionPull 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.
(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 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
Jon Schlinkert
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
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
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
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
53 existing vulnerabilities detected
Details
Score
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