Socket
Socket
Sign inDemoInstall

prompt-base

Package Overview
Dependencies
86
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.1.0

126

index.js

@@ -62,3 +62,2 @@ 'use strict';

this.onError = this.onError.bind(this);
// this.answer = this.getAnswer();
this.status = 'pending';

@@ -81,24 +80,2 @@ this.session = false;

/**
* Format the prompt message.
*
* ```js
* var answers = {};
* var Prompt = require('prompt-base');
* var prompt = new Prompt({
* name: 'name',
* message: 'What is your name?',
* transform: function(input) {
* return input.toUpperCase();
* }
* });
* ```
* @return {String}
* @api public
*/
Prompt.prototype.format = function(msg) {
return this.prefix + log.bold(msg) + ' ';
};
/**
* Modify the answer value before it's returned. Must

@@ -122,11 +99,10 @@ * return a string or promise.

Prompt.prototype.transform = function(answer) {
answer = this.getAnswer(answer);
Prompt.prototype.transform = function(input) {
if (typeof this.options.transform === 'function') {
return this.options.transform.call(this, answer);
return this.options.transform.call(this, input);
}
if (typeof this.options.filter === 'function') {
return this.options.filter.call(this, answer);
return this.options.filter.call(this, input);
}
return answer;
return input;
};

@@ -310,11 +286,4 @@

var append = this.renderError(state);
var message = this.message;
var message = this.renderMessage();
this.emit('render', {
state: state,
message: this.message,
status: this.status,
append: append
});
switch (this.status) {

@@ -331,2 +300,3 @@ case 'help':

case 'interacted':
case 'submitted':
default: {

@@ -338,15 +308,27 @@ message += this.renderOutput();

this.ui.render(message, append);
var render = {
state: state,
message: message,
status: this.status,
append: append
};
this.emit('render', render);
this.ui.render(render.message, render.append);
};
/**
* Render an error message in the prompt, when `valid` is
* false or a string. This is used when a validation method
* either returns `false`, indicating that the input
* was invalid, or the method returns a string, indicating
* that a custom error message should be rendered. A custom
* error message may also be defined on `options.errorMessage`.
* Format the prompt message.
*
* @default `>> invalid input`
* @param {boolean|string|undefined} `valid`
* ```js
* var answers = {};
* var Prompt = require('prompt-base');
* var prompt = new Prompt({
* name: 'name',
* message: 'What is your name?',
* transform: function(input) {
* return input.toUpperCase();
* }
* });
* ```
* @return {String}

@@ -356,10 +338,4 @@ * @api public

Prompt.prototype.renderError = function(valid) {
if (valid === false) {
return this.options.errorMessage || this.errorMessage;
}
if (typeof valid === 'string') {
return log.red('>> ') + valid;
}
return '';
Prompt.prototype.renderMessage = function() {
return this.prefix + log.bold(this.message) + ' ';
};

@@ -392,2 +368,26 @@

/**
* Render an error message in the prompt, when `valid` is
* false or a string. This is used when a validation method
* either returns `false`, indicating that the input
* was invalid, or the method returns a string, indicating
* that a custom error message should be rendered. A custom
* error message may also be defined on `options.errorMessage`.
*
* @default `>> invalid input`
* @param {boolean|string|undefined} `valid`
* @return {String}
* @api public
*/
Prompt.prototype.renderError = function(valid) {
if (valid === false) {
return this.options.errorMessage || this.errorMessage;
}
if (typeof valid === 'string') {
return log.red('>> ') + valid;
}
return '';
};
/**
* Called by [render](#render) to render the readline `line`

@@ -462,3 +462,2 @@ * when `prompt.status` is anything besides `answered`, which

this.choices.position = this.position;
var answer = this.getAnswer(input);
var self = this;

@@ -472,2 +471,3 @@

if (key.name === 'line') {
input = this.getAnswer(input, key);
this.status = 'submitted';

@@ -491,3 +491,3 @@ }

Promise.resolve(this.validate(answer, key))
Promise.resolve(this.validate(input, key))
.then(function(state) {

@@ -499,3 +499,4 @@ var action = self.action(key.name);

if (key.name === 'line' && state === true) {
return self.submitAnswer(answer);
self.render(state);
return self.submitAnswer(input);
}

@@ -551,4 +552,4 @@

Prompt.prototype.getAnswer = function(input) {
this.answer = this.question.getAnswer(input || this.getDefault());
Prompt.prototype.getAnswer = function(input, key) {
this.answer = this.question.getAnswer(input || this.getDefault(), key);
return this.answer;

@@ -563,10 +564,9 @@ };

Prompt.prototype.submitAnswer = function(input) {
Prompt.prototype.submitAnswer = function(answer) {
setImmediate(function() {
this.status = 'answered';
this.end();
this.answer = this.getAnswer(input);
this.emit('answer', this.answer);
this.emit('answer', answer);
this.rl.line = '';
this.callback(this.answer);
this.callback(answer);
}.bind(this));

@@ -720,3 +720,3 @@ };

get: function() {
return this.format(this.question.message);
return this.question.message;
}

@@ -723,0 +723,0 @@ });

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

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

@@ -101,24 +101,4 @@ # 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)

### [.format](index.js#L97)
### [.transform](index.js#L97)
Format the prompt message.
* `returns` **{String}**
**Example**
```js
var answers = {};
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'name',
message: 'What is your name?',
transform: function(input) {
return input.toUpperCase();
}
});
```
### [.transform](index.js#L120)
Modify the answer value before it's returned. Must return a string or promise.

@@ -142,3 +122,3 @@

### [.validate](index.js#L159)
### [.validate](index.js#L135)

@@ -168,3 +148,3 @@ Validate user input on `keypress` events and the answer value when it's submitted by the `line` event (when the user hits <kbd>enter</kbd>. This may be overridden in custom prompts. If the function returns `false`, either `question.errorMessage` or the default validation error message (`invalid input`) is used. Must return a boolean, string or promise.

### [.when](index.js#L190)
### [.when](index.js#L166)

@@ -191,3 +171,3 @@ A custom `.when` function may be defined to determine

### [.ask](index.js#L216)
### [.ask](index.js#L192)

@@ -215,3 +195,3 @@ Run the prompt with the given `callback` function.

### [.run](index.js#L257)
### [.run](index.js#L233)

@@ -242,3 +222,3 @@ Run the prompt and resolve answers. If [when](#when) is defined and returns false, the prompt will be skipped.

### [.render](index.js#L301)
### [.render](index.js#L277)

@@ -253,18 +233,24 @@ (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.

### [.renderError](index.js#L350)
### [.renderMessage](index.js#L332)
Render an error message in the prompt, when `valid` is
false or a string. This is used when a validation method
either returns `false`, indicating that the input
was invalid, or the method returns a string, indicating
that a custom error message should be rendered. A custom
error message may also be defined on `options.errorMessage`.
Format the prompt message.
**Params**
* `valid` **{boolean|string|undefined}**
* `returns` **{String}**
### [.renderHelp](index.js#L374)
**Example**
```js
var answers = {};
var Prompt = require('prompt-base');
var prompt = new Prompt({
name: 'name',
message: 'What is your name?',
transform: function(input) {
return input.toUpperCase();
}
});
```
### [.renderHelp](index.js#L350)
Called by [render](#render) to render a help message when the

@@ -283,2 +269,16 @@ `prompt.status` is `initialized` or `help` (usually when the

### [.renderError](index.js#L374)
Render an error message in the prompt, when `valid` is
false or a string. This is used when a validation method
either returns `false`, indicating that the input
was invalid, or the method returns a string, indicating
that a custom error message should be rendered. A custom
error message may also be defined on `options.errorMessage`.
**Params**
* `valid` **{boolean|string|undefined}**
* `returns` **{String}**
### [.renderOutput](index.js#L393)

@@ -331,3 +331,3 @@

### [.onError](index.js#L510)
### [.onError](index.js#L511)

@@ -342,11 +342,11 @@ Default error event handler. If an `error` listener exist, an `error`

### [.getDefault](index.js#L525)
### [.getDefault](index.js#L526)
Get the answer to use. This can be overridden in custom prompts.
### [.getAnswer](index.js#L539)
### [.getAnswer](index.js#L540)
Get the answer to use. This can be overridden in custom prompts.
### [.submitAnswer](index.js#L550)
### [.submitAnswer](index.js#L551)

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

| --- | --- |
| 107 | [jonschlinkert](https://github.com/jonschlinkert) |
| 110 | [jonschlinkert](https://github.com/jonschlinkert) |
| 6 | [doowb](https://github.com/doowb) |

@@ -586,2 +586,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 23, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 24, 2017._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc