Socket
Socket
Sign inDemoInstall

inquirer

Package Overview
Dependencies
Maintainers
2
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inquirer - npm Package Compare versions

Comparing version 5.2.0 to 6.0.0

lib/prompts/number.js

1

lib/inquirer.js

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

this.registerPrompt('input', require('./prompts/input'));
this.registerPrompt('number', require('./prompts/number'));
this.registerPrompt('confirm', require('./prompts/confirm'));

@@ -59,0 +60,0 @@ this.registerPrompt('rawlist', require('./prompts/rawlist'));

38

lib/prompts/base.js

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

var runAsync = require('run-async');
var { filter, flatMap, share, take, takeUntil } = require('rxjs/operators');
var Choices = require('../objects/choices');

@@ -31,6 +32,3 @@ var ScreenManager = require('../utils/screen-manager');

// Check to make sure prompt requirements are there
if (!this.opt.message) {
this.throwParamError('message');
}
// Make sure name is present
if (!this.opt.name) {

@@ -40,2 +38,7 @@ this.throwParamError('name');

// Set default message if no message defined
if (!this.opt.message) {
this.opt.message = this.opt.name + ':';
}
// Normalize choices

@@ -91,6 +94,6 @@ if (Array.isArray(this.opt.choices)) {

var validate = runAsync(this.opt.validate);
var filter = runAsync(this.opt.filter);
var validation = submit
.flatMap(value =>
filter(value, self.answers).then(
var asyncFilter = runAsync(this.opt.filter);
var validation = submit.pipe(
flatMap(value =>
asyncFilter(value, self.answers).then(
filteredValue =>

@@ -103,7 +106,11 @@ validate(filteredValue, self.answers).then(

)
)
.share();
),
share()
);
var success = validation.filter(state => state.isValid === true).take(1);
var error = validation.filter(state => state.isValid !== true).takeUntil(success);
var success = validation.pipe(filter(state => state.isValid === true), take(1));
var error = validation.pipe(
filter(state => state.isValid !== true),
takeUntil(success)
);

@@ -131,3 +138,8 @@ return {

if (this.opt.default != null && this.status !== 'answered') {
message += chalk.dim('(' + this.opt.default + ') ');
// If default password is supplied, hide it
if (this.opt.type === 'password') {
message += chalk.italic.dim('[hidden] ');
} else {
message += chalk.dim('(' + this.opt.default + ') ');
}
}

@@ -134,0 +146,0 @@

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

var figures = require('figures');
var { map, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -52,3 +53,3 @@ var observe = require('../utils/events');

var validation = this.handleSubmitEvents(
events.line.map(this.getCurrentValue.bind(this))
events.line.pipe(map(this.getCurrentValue.bind(this)))
);

@@ -58,10 +59,16 @@ validation.success.forEach(this.onEnd.bind(this));

events.normalizedUpKey.takeUntil(validation.success).forEach(this.onUpKey.bind(this));
events.normalizedUpKey
.pipe(takeUntil(validation.success))
.forEach(this.onUpKey.bind(this));
events.normalizedDownKey
.takeUntil(validation.success)
.pipe(takeUntil(validation.success))
.forEach(this.onDownKey.bind(this));
events.numberKey.takeUntil(validation.success).forEach(this.onNumberKey.bind(this));
events.spaceKey.takeUntil(validation.success).forEach(this.onSpaceKey.bind(this));
events.aKey.takeUntil(validation.success).forEach(this.onAllKey.bind(this));
events.iKey.takeUntil(validation.success).forEach(this.onInverseKey.bind(this));
events.numberKey
.pipe(takeUntil(validation.success))
.forEach(this.onNumberKey.bind(this));
events.spaceKey
.pipe(takeUntil(validation.success))
.forEach(this.onSpaceKey.bind(this));
events.aKey.pipe(takeUntil(validation.success)).forEach(this.onAllKey.bind(this));
events.iKey.pipe(takeUntil(validation.success)).forEach(this.onInverseKey.bind(this));

@@ -68,0 +75,0 @@ // Init the prompt

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

var chalk = require('chalk');
var { take, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -48,5 +49,5 @@ var observe = require('../utils/events');

var events = observe(this.rl);
events.keypress.takeUntil(events.line).forEach(this.onKeypress.bind(this));
events.keypress.pipe(takeUntil(events.line)).forEach(this.onKeypress.bind(this));
events.line.take(1).forEach(this.onEnd.bind(this));
events.line.pipe(take(1)).forEach(this.onEnd.bind(this));

@@ -53,0 +54,0 @@ // Init

@@ -7,6 +7,6 @@ 'use strict';

var chalk = require('chalk');
var ExternalEditor = require('external-editor');
var editAsync = require('external-editor').editAsync;
var Base = require('./base');
var observe = require('../utils/events');
var Rx = require('rxjs/Rx');
var { Subject } = require('rxjs');

@@ -23,3 +23,3 @@ class EditorPrompt extends Base {

this.editorResult = new Rx.Subject();
this.editorResult = new Subject();

@@ -74,3 +74,3 @@ // Open Editor on "line" (Enter Key)

this.rl.pause();
ExternalEditor.editAsync(this.currentText, this.endExternalEditor.bind(this));
editAsync(this.currentText, this.endExternalEditor.bind(this));
}

@@ -77,0 +77,0 @@

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

var chalk = require('chalk');
var { map, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -57,3 +58,3 @@ var Separator = require('../objects/separator');

var validation = this.handleSubmitEvents(
events.line.map(this.getCurrentValue.bind(this))
events.line.pipe(map(this.getCurrentValue.bind(this)))
);

@@ -63,3 +64,3 @@ validation.success.forEach(this.onSubmit.bind(this));

this.keypressObs = events.keypress
.takeUntil(validation.success)
.pipe(takeUntil(validation.success))
.forEach(this.onKeypress.bind(this));

@@ -66,0 +67,0 @@

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

var chalk = require('chalk');
var { map, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -23,3 +24,3 @@ var observe = require('../utils/events');

var events = observe(this.rl);
var submit = events.line.map(this.filterInput.bind(this));
var submit = events.line.pipe(map(this.filterInput.bind(this)));

@@ -30,3 +31,5 @@ var validation = this.handleSubmitEvents(submit);

events.keypress.takeUntil(validation.success).forEach(this.onKeypress.bind(this));
events.keypress
.pipe(takeUntil(validation.success))
.forEach(this.onKeypress.bind(this));

@@ -46,13 +49,19 @@ // Init

var bottomContent = '';
var appendContent = '';
var message = this.getQuestion();
var transformer = this.opt.transformer;
var isFinal = this.status === 'answered';
if (this.status === 'answered') {
message += chalk.cyan(this.answer);
} else if (transformer) {
message += transformer(this.rl.line, this.answers);
if (isFinal) {
appendContent = this.answer;
} else {
message += this.rl.line;
appendContent = this.rl.line;
}
if (transformer) {
message += transformer(appendContent, this.answers, { isFinal });
} else {
message += isFinal ? chalk.cyan(appendContent) : appendContent;
}
if (error) {

@@ -59,0 +68,0 @@ bottomContent = chalk.red('>> ') + error;

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

var runAsync = require('run-async');
var { flatMap, map, take, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -55,9 +56,13 @@ var observe = require('../utils/events');

var events = observe(this.rl);
events.normalizedUpKey.takeUntil(events.line).forEach(this.onUpKey.bind(this));
events.normalizedDownKey.takeUntil(events.line).forEach(this.onDownKey.bind(this));
events.numberKey.takeUntil(events.line).forEach(this.onNumberKey.bind(this));
events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
events.normalizedDownKey
.pipe(takeUntil(events.line))
.forEach(this.onDownKey.bind(this));
events.numberKey.pipe(takeUntil(events.line)).forEach(this.onNumberKey.bind(this));
events.line
.take(1)
.map(this.getCurrentValue.bind(this))
.flatMap(value => runAsync(self.opt.filter)(value).catch(err => err))
.pipe(
take(1),
map(this.getCurrentValue.bind(this)),
flatMap(value => runAsync(self.opt.filter)(value).catch(err => err))
)
.forEach(this.onSubmit.bind(this));

@@ -64,0 +69,0 @@

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

var chalk = require('chalk');
var { map, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -34,3 +35,3 @@ var observe = require('../utils/events');

// Once user confirm (enter key)
var submit = events.line.map(this.filterInput.bind(this));
var submit = events.line.pipe(map(this.filterInput.bind(this)));

@@ -42,3 +43,5 @@ var validation = this.handleSubmitEvents(submit);

if (this.opt.mask) {
events.keypress.takeUntil(validation.success).forEach(this.onKeypress.bind(this));
events.keypress
.pipe(takeUntil(validation.success))
.forEach(this.onKeypress.bind(this));
}

@@ -45,0 +48,0 @@

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

var chalk = require('chalk');
var { map, takeUntil } = require('rxjs/operators');
var Base = require('./base');

@@ -61,3 +62,3 @@ var Separator = require('../objects/separator');

var events = observe(this.rl);
var submit = events.line.map(this.getCurrentValue.bind(this));
var submit = events.line.pipe(map(this.getCurrentValue.bind(this)));

@@ -68,3 +69,5 @@ var validation = this.handleSubmitEvents(submit);

events.keypress.takeUntil(validation.success).forEach(this.onKeypress.bind(this));
events.keypress
.pipe(takeUntil(validation.success))
.forEach(this.onKeypress.bind(this));

@@ -71,0 +74,0 @@ // Init the prompt

'use strict';
var _ = require('lodash');
var Rx = require('rxjs/Rx');
var { defer, empty, from, of } = require('rxjs');
var { concatMap, filter, publish, reduce } = require('rxjs/operators');
var runAsync = require('run-async');

@@ -30,8 +31,8 @@ var utils = require('../utils/utils');

// be using the exact same object in memory.
var obs = _.isArray(questions) ? Rx.Observable.from(questions) : questions;
var obs = _.isArray(questions) ? from(questions) : questions;
this.process = obs
.concatMap(this.processQuestion.bind(this))
// `publish` creates a hot Observable. It prevents duplicating prompts.
.publish();
this.process = obs.pipe(
concatMap(this.processQuestion.bind(this)),
publish() // Creates a hot Observable. It prevents duplicating prompts.
);

@@ -41,6 +42,8 @@ this.process.connect();

return this.process
.reduce((answers, answer) => {
_.set(this.answers, answer.name, answer.answer);
return this.answers;
}, {})
.pipe(
reduce((answers, answer) => {
_.set(this.answers, answer.name, answer.answer);
return this.answers;
}, {})
)
.toPromise(Promise)

@@ -54,6 +57,6 @@ .then(this.onCompletion.bind(this));

onCompletion(answers) {
onCompletion() {
this.close();
return answers;
return this.answers;
}

@@ -63,18 +66,19 @@

question = _.clone(question);
return Rx.Observable.defer(() => {
var obs = Rx.Observable.of(question);
return defer(() => {
var obs = of(question);
return obs
.concatMap(this.setDefaultType.bind(this))
.concatMap(this.filterIfRunnable.bind(this))
.concatMap(() =>
return obs.pipe(
concatMap(this.setDefaultType.bind(this)),
concatMap(this.filterIfRunnable.bind(this)),
concatMap(() =>
utils.fetchAsyncQuestionProperty(question, 'message', this.answers)
)
.concatMap(() =>
),
concatMap(() =>
utils.fetchAsyncQuestionProperty(question, 'default', this.answers)
)
.concatMap(() =>
),
concatMap(() =>
utils.fetchAsyncQuestionProperty(question, 'choices', this.answers)
)
.concatMap(this.fetchAnswer.bind(this));
),
concatMap(this.fetchAnswer.bind(this))
);
});

@@ -86,4 +90,4 @@ }

this.activePrompt = new Prompt(question, this.rl, this.answers);
return Rx.Observable.defer(() =>
Rx.Observable.fromPromise(
return defer(() =>
from(
this.activePrompt.run().then(answer => ({ name: question.name, answer: answer }))

@@ -99,3 +103,3 @@ )

}
return Rx.Observable.defer(() => Rx.Observable.of(question));
return defer(() => of(question));
}

@@ -105,12 +109,12 @@

if (question.when === false) {
return Rx.Observable.empty();
return empty();
}
if (!_.isFunction(question.when)) {
return Rx.Observable.of(question);
return of(question);
}
var answers = this.answers;
return Rx.Observable.defer(() =>
Rx.Observable.fromPromise(
return defer(() =>
from(
runAsync(question.when)(answers).then(shouldRun => {

@@ -121,3 +125,3 @@ if (shouldRun) {

})
).filter(val => val != null)
).pipe(filter(val => val != null))
);

@@ -124,0 +128,0 @@ }

'use strict';
var Rx = require('rxjs/Rx');
var { fromEvent } = require('rxjs');
var { filter, map, share } = require('rxjs/operators');

@@ -9,33 +10,36 @@ function normalizeKeypressEvents(value, key) {

module.exports = function(rl) {
var keypress = Rx.Observable.fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
var keypress = fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
// Ignore `enter` key. On the readline, we only care about the `line` event.
.filter(({ key }) => key.name !== 'enter' && key.name !== 'return');
.pipe(filter(({ key }) => key.name !== 'enter' && key.name !== 'return'));
return {
line: Rx.Observable.fromEvent(rl, 'line'),
line: fromEvent(rl, 'line'),
keypress: keypress,
normalizedUpKey: keypress
.filter(
normalizedUpKey: keypress.pipe(
filter(
({ key }) =>
key.name === 'up' || key.name === 'k' || (key.name === 'p' && key.ctrl)
)
.share(),
),
share()
),
normalizedDownKey: keypress
.filter(
normalizedDownKey: keypress.pipe(
filter(
({ key }) =>
key.name === 'down' || key.name === 'j' || (key.name === 'n' && key.ctrl)
)
.share(),
),
share()
),
numberKey: keypress
.filter(e => e.value && '123456789'.indexOf(e.value) >= 0)
.map(e => Number(e.value))
.share(),
numberKey: keypress.pipe(
filter(e => e.value && '123456789'.indexOf(e.value) >= 0),
map(e => Number(e.value)),
share()
),
spaceKey: keypress.filter(({ key }) => key && key.name === 'space').share(),
aKey: keypress.filter(({ key }) => key && key.name === 'a').share(),
iKey: keypress.filter(({ key }) => key && key.name === 'i').share()
spaceKey: keypress.pipe(filter(({ key }) => key && key.name === 'space'), share()),
aKey: keypress.pipe(filter(({ key }) => key && key.name === 'a'), share()),
iKey: keypress.pipe(filter(({ key }) => key && key.name === 'i'), share())
};
};
'use strict';
var _ = require('lodash');
var Rx = require('rxjs/Rx');
var { from, of } = require('rxjs');
var runAsync = require('run-async');

@@ -17,6 +17,6 @@

if (!_.isFunction(question[prop])) {
return Rx.Observable.of(question);
return of(question);
}
return Rx.Observable.fromPromise(
return from(
runAsync(question[prop])(answers).then(value => {

@@ -23,0 +23,0 @@ question[prop] = value;

{
"name": "inquirer",
"version": "5.2.0",
"version": "6.0.0",
"description":

@@ -20,3 +20,3 @@ "A collection of common interactive command line user interfaces.",

"eslint-config-prettier": "^2.4.0",
"eslint-config-xo": "^0.20.0",
"eslint-config-xo": "^0.22.1",
"eslint-plugin-prettier": "^2.2.0",

@@ -28,5 +28,5 @@ "husky": "^0.14.3",

"nsp": "^3.0.0",
"nyc": "^11.3.0",
"nyc": "^12.0.1",
"prettier": "^1.7.0",
"sinon": "^4.0.0"
"sinon": "^5.0.0"
},

@@ -47,3 +47,3 @@ "scripts": {

"cli-width": "^2.0.0",
"external-editor": "^2.1.0",
"external-editor": "^3.0.0",
"figures": "^2.0.0",

@@ -53,3 +53,3 @@ "lodash": "^4.3.0",

"run-async": "^2.2.0",
"rxjs": "^5.5.2",
"rxjs": "^6.1.0",
"string-width": "^2.1.0",

@@ -56,0 +56,0 @@ "strip-ansi": "^4.0.0",

@@ -110,4 +110,4 @@ Inquirer.js

- **name**: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
- **message**: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers.
- **default**: (String|Number|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
- **message**: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of `name` (followed by a colon).
- **default**: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
- **choices**: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers.

@@ -117,3 +117,3 @@ Array values can be simple `strings`, or `objects` containing a `name` (to display in list), a `value` (to save in the answers hash) and a `short` (to display after selection) properties. The choices array can also contain [a `Separator`](#separator).

- **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
- **transformer**: (Function) Receive the user input and answers hash, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
- **transformer**: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
- **when**: (Function, Boolean) Receive the current user answers hash and should return `true` or `false` depending on whether or not this question should be asked. The value can also be a simple boolean.

@@ -393,2 +393,7 @@ - **pageSize**: (Number) Change the number of lines that will be rendered when using `list`, `rawList`, `expand` or `checkbox`.

[__inquirer-fuzzy-path__](https://github.com/adelsz/inquirer-fuzzy-path)<br>
Prompt for fuzzy file/directory selection.<br>
<br>
![inquirer-fuzzy-path](https://raw.githubusercontent.com/adelsz/inquirer-fuzzy-path/master/recording.gif)
[__inquirer-chalk-pipe__](https://github.com/LitoMore/inquirer-chalk-pipe)<br>

@@ -401,1 +406,6 @@ Prompt for input chalk-pipe style strings<br>

Searchable Inquirer checkbox<br>
[__inquirer-prompt-suggest__](https://github.com/olistic/inquirer-prompt-suggest)<br>
Inquirer prompt for your less creative users.
![inquirer-prompt-suggest](https://user-images.githubusercontent.com/5600126/40391192-d4f3d6d0-5ded-11e8-932f-4b75b642c09e.gif)
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