Socket
Socket
Sign inDemoInstall

prompt-base

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompt-base - npm Package Compare versions

Comparing version 3.0.5 to 4.0.0

17

changelog.md
# Release history
## v4.0.0
**Changed**
- no longer throws an error when question name is undefined
**Added**
- adds support for defining `prompt.question.default` as a function
- adds support for defining `prompt.question.choices` as a function
## v3.0.0
**Added**
- adds initial support for `prompt.context`, an object that can be passed around at runtime to simplify rendering. Future releases will gradually improve context handling until we make a full transition to redux, or redux-like state. Throughout this process, special care will be taken to ensure that the API is the same until the transition to redux, at which time we'll fully document any API changes.
## v2.0.2

@@ -4,0 +21,0 @@

70

index.js

@@ -75,3 +75,3 @@ 'use strict';

this.initListeners();
};
}

@@ -266,2 +266,7 @@ /**

* Get the answer to use. This can be overridden in custom prompts.
*
* ```js
* console.log(prompt.getDefault());
* ```
* @return {String}
* @api public

@@ -271,12 +276,16 @@ */

Prompt.prototype.getDefault = function() {
var def = this.question.default;
var val = this.question.default;
if (typeof val === 'function') {
val = val.call(this);
}
if (this.choices && this.choices.length) {
if (def != null) {
if (val != null) {
this.question.default = null;
this.choices.check(def);
this.choices.default = def;
if (Array.isArray(def)) def = def[0];
var choice = this.choices.get(def);
this.choices.check(val);
this.choices.default = val;
if (Array.isArray(val)) val = val[0];
var choice = this.choices.get(val);
if (choice) {
def = choice.name;
val = choice.name;
this.position = choice.index;

@@ -286,4 +295,4 @@ }

}
this.initialDefault = def;
return def;
this.initialDefault = val;
return val;
};

@@ -293,2 +302,7 @@

* Get the error message to use. This can be overridden in custom prompts.
*
* ```js
* console.log(prompt.getError());
* ```
* @return {String}
* @api public

@@ -303,2 +317,7 @@ */

* Get the help message to use. This can be overridden in custom prompts.
*
* ```js
* console.log(prompt.getHelp());
* ```
* @return {String}
* @api public

@@ -313,2 +332,7 @@ */

* Get the answer to use. This can be overridden in custom prompts.
*
* ```js
* console.log(prompt.getAnswer());
* ```
* @return {String}
* @api public

@@ -335,2 +359,3 @@ */

* ```
* @return {undefined}
* @api public

@@ -350,10 +375,16 @@ */

line: this.rl.line,
keypress: this.keypress,
answer: this.answer,
default: this.getDefault(),
original: this.renderMessage(this),
banner: '',
header: '',
prefix: this.prefix,
message: this.message,
prefix: this.prefix,
banner: '',
input: '',
footer: '',
append: '',
output: '',
error: '',
hint: '',
help: ''

@@ -499,3 +530,7 @@ };

Prompt.prototype.renderAnswer = function() {
return log.cyan(this.renderMask(this.answer));
var answer = this.renderMask(this.answer);
if (answer != null) {
return log.cyan(answer);
}
return '';
};

@@ -549,2 +584,4 @@

var action = self.action(key.name);
input = input || '';
if (typeof action === 'function') {

@@ -558,10 +595,9 @@ this.position = action.call(this.actions, this.position, key);

// re-render the prompt in the terminal
self.render(state);
// handle the "enter" keypress event
if (key.name === 'line' && state === true) {
self.render(state);
return self.submitAnswer(input);
}
// re-render the prompt in the terminal
self.render(state);
})

@@ -568,0 +604,0 @@ .catch(this.onError);

{
"name": "prompt-base",
"description": "Base prompt module used for creating custom prompts.",
"version": "3.0.5",
"version": "4.0.0",
"homepage": "https://github.com/enquirer/prompt-base",

@@ -32,3 +32,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"prompt-actions": "^3.0.2",
"prompt-question": "^4.0.3",
"prompt-question": "^5.0.0",
"readline-ui": "^2.2.3",

@@ -42,5 +42,5 @@ "readline-utils": "^2.2.1",

"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-format-md": "^0.1.12",
"gulp-istanbul": "^1.1.1",
"gulp-eslint": "^4.0.0",
"gulp-format-md": "^1.0.0",
"gulp-istanbul": "^1.1.2",
"gulp-mocha": "^3.0.1",

@@ -47,0 +47,0 @@ "mocha": "^3.4.2",

@@ -13,9 +13,5 @@ # prompt-base [![NPM version](https://img.shields.io/npm/v/prompt-base.svg?style=flat)](https://www.npmjs.com/package/prompt-base) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-base.svg?style=flat)](https://npmjs.org/package/prompt-base) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-base.svg?style=flat)](https://npmjs.org/package/prompt-base) [![Linux Build Status](https://img.shields.io/travis/enquirer/prompt-base.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/prompt-base) [![Windows Build Status](https://img.shields.io/appveyor/ci/enquirer/prompt-base.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/enquirer/prompt-base)

* no message (uses `${name}?` as message)
* options.default (string, array)
* options.when
## Release history
See [the changlog](changelog.md) for details.
See [the changelog](changelog.md) for detailed release history.

@@ -218,22 +214,56 @@ ## What is this?

### [.getDefault](index.js#L268)
### [.getDefault](index.js#L273)
Get the answer to use. This can be overridden in custom prompts.
### [.getError](index.js#L292)
* `returns` **{String}**
**Example**
```js
console.log(prompt.getDefault());
```
### [.getError](index.js#L306)
Get the error message to use. This can be overridden in custom prompts.
### [.getHelp](index.js#L301)
* `returns` **{String}**
**Example**
```js
console.log(prompt.getError());
```
### [.getHelp](index.js#L320)
Get the help message to use. This can be overridden in custom prompts.
### [.getAnswer](index.js#L310)
* `returns` **{String}**
**Example**
```js
console.log(prompt.getHelp());
```
### [.getAnswer](index.js#L334)
Get the answer to use. This can be overridden in custom prompts.
### [.render](index.js#L331)
* `returns` **{String}**
**Example**
```js
console.log(prompt.getAnswer());
```
### [.render](index.js#L356)
(Re-)render the prompt message, along with any help or error messages, user input, choices, list items, and so on. This is called to render the initial prompt, then it's called again each time the prompt changes, such as on keypress events (when the user enters input, or a multiple-choice option is selected). This method may be overridden in custom prompts, but it's recommended that you override the more specific render "status" methods instead.
* `returns` **{undefined}**
**Example**

@@ -245,3 +275,3 @@

### [.renderMessage](index.js#L403)
### [.renderMessage](index.js#L434)

@@ -266,3 +296,3 @@ Format the prompt message.

### [.renderHelp](index.js#L421)
### [.renderHelp](index.js#L452)

@@ -282,3 +312,3 @@ Called by [render](#render) to render a help message when the

### [.renderError](index.js#L444)
### [.renderError](index.js#L475)

@@ -297,3 +327,3 @@ Render an error message in the prompt, when `valid` is

### [.renderOutput](index.js#L463)
### [.renderOutput](index.js#L494)

@@ -306,3 +336,3 @@ Called by [render](#render) to render the readline `line`

### [.renderMask](index.js#L477)
### [.renderMask](index.js#L508)

@@ -316,3 +346,3 @@ Mask user input. Called by [renderOutput](#renderOutput),

### [.renderAnswer](index.js#L489)
### [.renderAnswer](index.js#L520)

@@ -324,3 +354,3 @@ Render the user's "answer". Called by [render](#render) when

### [.action](index.js#L505)
### [.action](index.js#L540)

@@ -338,3 +368,3 @@ Get action `name`, or set action `name` with the given `fn`.

### [.dispatch](index.js#L522)
### [.dispatch](index.js#L557)

@@ -349,3 +379,3 @@ Move the cursor in the given `direction` when a `keypress`

### [.onError](index.js#L567)
### [.onError](index.js#L603)

@@ -360,3 +390,3 @@ Default error event handler. If an `error` listener exist, an `error`

### [.submitAnswer](index.js#L583)
### [.submitAnswer](index.js#L619)

@@ -366,3 +396,3 @@ Re-render and pass the final answer to the callback.

### [.only](index.js#L607)
### [.only](index.js#L643)

@@ -379,3 +409,3 @@ Ensures that events for event `name` are only **registered** once and are disabled correctly when specified. This is different from `.once`, which only **emits** once.

### [.mute](index.js#L636)
### [.mute](index.js#L672)

@@ -396,3 +426,3 @@ Mutes the output stream that was used to create the readline interface, and returns a function for unmuting the stream. This is useful in unit tests.

### [.end](index.js#L656)
### [.end](index.js#L692)

@@ -403,3 +433,3 @@ Pause the readline and unmute the output stream that was

### [.resume](index.js#L671)
### [.resume](index.js#L707)

@@ -410,3 +440,3 @@ [Resume](https://nodejs.org/api/readline.html#readline_rl_resume) the readline input stream if it has been paused.

### [.choices](index.js#L724)
### [.choices](index.js#L760)

@@ -417,3 +447,3 @@ Getter for getting the choices array from the question.

### [.message](index.js#L741)
### [.message](index.js#L777)

@@ -424,3 +454,3 @@ Getter that returns `question.message` after passing it to [format](#format).

### [.symbol](index.js#L762)
### [.symbol](index.js#L798)

@@ -438,3 +468,3 @@ Getter/setter for getting the checkbox symbol to use.

### [.prefix](index.js#L788)
### [.prefix](index.js#L824)

@@ -452,3 +482,3 @@ Getter/setter that returns the prefix to use before `question.message`. The default value is a green `?`.

### [.ask](index.js#L816)
### [.ask](index.js#L852)

@@ -475,3 +505,3 @@ Static convenience method for running the [.ask](#ask) method. Takes the same arguments as the contructror.

### [.run](index.js#L842)
### [.run](index.js#L878)

@@ -498,3 +528,3 @@ Static convenience method for running the [.run](#run) method. Takes the same arguments as the contructror.

### [.Question](index.js#L858)
### [.Question](index.js#L894)

@@ -514,3 +544,3 @@ Create a new `Question`. See [prompt-question](https://github.com/enquirer/prompt-question) for more details.

### [.Choices](index.js#L872)
### [.Choices](index.js#L908)

@@ -530,3 +560,3 @@ Create a new `Choices` object. See [prompt-choices](https://github.com/enquirer/prompt-choices) for more details.

### [.Separator](index.js#L885)
### [.Separator](index.js#L921)

@@ -630,3 +660,3 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details.

| --- | --- |
| 142 | [jonschlinkert](https://github.com/jonschlinkert) |
| 147 | [jonschlinkert](https://github.com/jonschlinkert) |
| 6 | [doowb](https://github.com/doowb) |

@@ -666,2 +696,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 05, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 08, 2017._
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