Socket
Socket
Sign inDemoInstall

enquirer

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enquirer - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

lib/.DS_Store

2

index.js

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

return enquirer.prompt(questions);
}
};
utils.mixinEmitter(fn, new Events());

@@ -244,0 +244,0 @@ return fn;

@@ -8,10 +8,9 @@ 'use strict';

* Render a placeholder value with cursor and styling based on the
* position of the cursor. This function creates the illusion that
* position of the cursor.
*
*
* @param {Object} `prompt` Prompt instance
* @param {String} `input`
* @param {String} `initial`
* @param {Number} `pos`
* @param {Boolean} `showCursor`
* @param {Object} `prompt` Prompt instance.
* @param {String} `input` Input string.
* @param {String} `initial` The initial user-provided value.
* @param {Number} `pos` Current cursor position.
* @param {Boolean} `showCursor` Render a simulated cursor using the inverse primary style.
* @return {String} Returns the styled placeholder string.

@@ -21,5 +20,6 @@ * @api public

module.exports = (prompt, input = '', initial = '', pos, showCursor = true) => {
module.exports = (prompt, input = '', initial = '', pos, showCursor = true, color) => {
prompt.cursorHide();
let style = color || prompt.styles.placeholder;
let inverse = utils.inverse(prompt.styles.primary);

@@ -45,3 +45,3 @@ let output = input;

let raw = colors.unstyle(output + cursor);
return output + cursor + prompt.styles.placeholder(initial.slice(raw.length));
return output + cursor + style(initial.slice(raw.length));
}

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

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

let value = options[name] || state[name] || symbols[name];
let val = choice && choice[name] ? choice[name] : value;
let val = choice && choice[name] != null ? choice[name] : value;
let res = await utils.resolve(state, val, state, choice, i);

@@ -190,0 +190,0 @@ if (!res && choice && choice[name]) {

'use strict';
const colors = require('ansi-colors');
const Select = require('./select');

@@ -91,3 +90,3 @@

if (this.state.status !== 'pending') return super.render();
let style = this.options.highlight || this.styles.complement;
let style = this.options.highlight || this.styles.placeholder;
let color = highlight(this.state.input, style);

@@ -94,0 +93,0 @@ let choices = this.choices;

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

const placeholder = require('../placeholder');
const utils = require('../utils');

@@ -12,3 +11,6 @@ class FormPrompt extends SelectPrompt {

super({ ...options, multiple: true });
this.type = 'form';
this.initial = this.options.initial;
this.align = this.options.align || 'right';
this.emptyError = '';
this.values = {};

@@ -26,16 +28,2 @@ }

// async toChoice(...args) {
// let choice = await super.toChoice(...args);
// if (this.store) {
// choice.state = this.store.get(choice.name, { past: [], present: '' });
// choice.initial = choice.initial || choice.state.present;
// choice.state.present = choice.initial;
// } else if (!choice.initial) {
// choice.initial = choice.value;
// }
// return choice;
// }
dispatch(ch) {

@@ -46,7 +34,7 @@ return !!ch && this.append(ch);

append(s) {
let choice = this.focused;
if (!choice) return this.alert();
let { cursor, input } = choice;
choice.value = choice.input = input.slice(0, cursor) + s + input.slice(cursor);
choice.cursor++;
let ch = this.focused;
if (!ch) return this.alert();
let { cursor, input } = ch;
ch.value = ch.input = input.slice(0, cursor) + s + input.slice(cursor);
ch.cursor++;
return this.render();

@@ -56,7 +44,7 @@ }

delete() {
let choice = this.focused;
if (!choice || choice.cursor <= 0) return this.alert();
let { cursor, input } = choice;
choice.value = choice.input = input.slice(0, cursor - 1) + input.slice(cursor);
choice.cursor--;
let ch = this.focused;
if (!ch || ch.cursor <= 0) return this.alert();
let { cursor, input } = ch;
ch.value = ch.input = input.slice(0, cursor - 1) + input.slice(cursor);
ch.cursor--;
return this.render();

@@ -66,8 +54,8 @@ }

deleteForward() {
let choice = this.focused;
if (!choice) return this.alert();
let { cursor, input } = choice;
let ch = this.focused;
if (!ch) return this.alert();
let { cursor, input } = ch;
if (input[cursor] === void 0) return this.alert();
let str = `${input}`.slice(0, cursor) + `${input}`.slice(cursor + 1);
choice.value = choice.input = str;
ch.value = ch.input = str;
return this.render();

@@ -77,6 +65,6 @@ }

right() {
let choice = this.focused;
if (!choice) return this.alert();
if (choice.cursor >= choice.input.length) return this.alert();
choice.cursor++;
let ch = this.focused;
if (!ch) return this.alert();
if (ch.cursor >= ch.input.length) return this.alert();
ch.cursor++;
return this.render();

@@ -86,6 +74,6 @@ }

left() {
let choice = this.focused;
if (!choice) return this.alert();
if (choice.cursor <= 0) return this.alert();
choice.cursor--;
let ch = this.focused;
if (!ch) return this.alert();
if (ch.cursor <= 0) return this.alert();
ch.cursor--;
return this.render();

@@ -103,28 +91,23 @@ }

next() {
let choice = this.focused;
if (!choice) return this.alert();
let { initial, input } = choice;
let ch = this.focused;
if (!ch) return this.alert();
let { initial, input } = ch;
if (initial && initial.startsWith(input) && input !== initial) {
choice.value = choice.input = choice.initial;
choice.cursor = choice.value.length;
ch.value = ch.input = initial;
ch.cursor = ch.value.length;
return this.render();
}
if (input) {
return super.next();
}
this.alert();
return super.next();
}
prev() {
let choice = this.focused;
if (!choice) return this.alert();
if (choice.cursor === 0) {
return super.prev();
}
choice.value = choice.input = '';
choice.cursor = 0;
let ch = this.focused;
if (!ch) return this.alert();
if (ch.cursor === 0) return super.prev();
ch.value = ch.input = '';
ch.cursor = 0;
return this.render();
}
pointer() {
separator() {
return '';

@@ -137,2 +120,10 @@ }

pointer() {
return '';
}
indicator(choice) {
return choice.input ? '⦿' : '⊙';
}
async renderChoice(choice, i) {

@@ -142,18 +133,30 @@ await this.onChoice(choice, i);

let { state, styles, symbols } = this;
let { cursor, initial = '', name, input = '', separator = ':', validate } = choice;
let { cursor, initial = '', name, hint, input = '', separator } = choice;
let { muted, submitted, primary, danger } = styles;
// re-populate the values (answers) object
this.values[name] = input || initial;
let help = hint;
let focused = this.index === i;
let validate = choice.validate || (() => true);
let sep = separator || ' ' + this.styles.disabled(symbols.middot);
let msg = choice.message;
let message = choice.message.padStart(this.longest + 1, ' ');
let dotColor = choice.input ? 'success' : 'dark';
if (this.align === 'right') {
msg = msg.padStart(this.longest + 1, ' ');
}
if (typeof validate === 'function' && !(await validate.call(choice, input || initial))) {
dotColor = 'danger';
if (this.align === 'left') {
msg = msg.padEnd(this.longest + 1, ' ');
}
let symbol = choice.prefix || symbols.bullet;
let prefix = await utils.resolve(state, symbol, state, choice, i);
let dot = styles[dotColor](prefix);
// re-populate the form values (answers) object
let value = this.values[name] = (input || initial);
let color = input ? 'success' : 'dark';
if ((await validate.call(choice, value, this.state)) !== true) {
color = 'danger';
}
let style = styles[color];
let indicator = style(await this.indicator(choice, i)) + (choice.pad || '');
if (!input && initial) {

@@ -163,10 +166,17 @@ input = !state.submitted ? muted(initial) : initial;

let indent = this.indent(choice);
let line = () => [indent, indicator, msg + sep, input, help].filter(Boolean).join(' ');
if (state.submitted) {
return [dot, colors.unstyle(message) + separator, submitted(input)].join(' ');
msg = colors.unstyle(msg);
input = submitted(input);
help = '';
return line();
}
input = placeholder(this, choice.input, initial, cursor, this.index === i);
input = placeholder(this, choice.input, initial, cursor, focused, this.styles.muted);
if (!input) input = this.styles.muted(this.symbols.ellipsis);
if (this.index === i) {
message = primary(message);
if (focused) {
msg = primary(msg);
}

@@ -180,12 +190,5 @@

return [dot, message + separator, input, choice.help].filter(Boolean).join(' ');
return line();
}
// async renderChoices() {
// let choices = await Promise.all(this.visible.map(this.renderChoice.bind(this)));
// let visible = choices.join('\n');
// this.action = void 0;
// return visible;
// }
async submit() {

@@ -192,0 +195,0 @@ this.value = this.values;

@@ -7,4 +7,9 @@ 'use strict';

class SelectPrompt extends ArrayPrompt {
constructor(options) {
super(options);
this.emptyError = this.options.emptyError || 'No items were selected';
}
async dispatch(s, key) {
if (this.options.multiple) {
if (this.multiple) {
return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);

@@ -15,17 +20,21 @@ }

indicator(choice, i) {
return this.options.multiple ? super.indicator(choice, i) : '';
indicator(item, i) {
return this.multiple ? super.indicator(item, i) : '';
}
pointer(choice, i) {
return (!this.options.multiple || this.options.pointer) ? super.pointer(choice, i) : '';
pointer(item, i) {
return (!this.multiple || this.options.pointer) ? super.pointer(item, i) : '';
}
async renderChoice(choice, i) {
await this.onChoice(choice, i);
heading(msg, item, i) {
return this.styles.strong(msg);
}
async renderChoice(item, i) {
await this.onChoice(item, i);
let focused = this.index === i;
let pointer = await this.pointer(choice, i);
let indicator = await this.indicator(choice, i) + (choice.pad || '');
let hint = await choice.hint;
let pointer = await this.pointer(item, i);
let check = await this.indicator(item, i) + (item.pad || '');
let hint = await item.hint;

@@ -36,14 +45,20 @@ if (hint && !utils.hasColor(hint)) {

let ind = choice.indent;
let message = await this.resolve(choice.message, this.state, choice, i);
let line = () => [ind + pointer + indicator, message, hint].filter(Boolean).join(' ');
let ind = this.indent(item);
let msg = await this.resolve(item.message, this.state, item, i);
let line = () => [ind + pointer + check, msg, hint].filter(Boolean).join(' ');
if (choice.disabled) {
message = this.styles.disabled(message);
if (item.role === 'heading') {
msg = this.heading(msg, item, i);
return line();
}
if (item.disabled) {
msg = this.styles.disabled(msg);
return line();
}
if (focused) {
message = this.styles.heading(message);
msg = this.styles.heading(msg);
}
return line();

@@ -63,3 +78,3 @@ }

if (Array.isArray(this.selected)) {
return this.selected.map(choice => this.styles.primary(choice.name)).join(', ');
return this.selected.map(item => this.styles.primary(item.name)).join(', ');
}

@@ -76,4 +91,7 @@ return this.styles.primary(this.selected.name);

let prompt = [prefix, message, separator].filter(Boolean).join(' ');
this.state.prompt = prompt;
let prompt = '';
if (this.options.promptLine !== false) {
prompt = [prefix, message, separator].filter(Boolean).join(' ');
this.state.prompt = prompt;
}

@@ -89,4 +107,4 @@ let header = await this.header();

if (submitted && this.options.multiple && !output && !body) {
prompt += this.styles.danger('No items were selected');
if (submitted && !output && !body && this.multiple && this.emptyError != null) {
prompt += this.styles.danger(this.emptyError);
}

@@ -93,0 +111,0 @@

'use strict';
const { reorder, scrollUp, scrollDown, isObject, swap } = require('../utils');
const { reorder, scrollUp, scrollDown, isObject, swap, set } = require('../utils');
const colors = require('ansi-colors');
const Prompt = require('../prompt');

@@ -10,2 +11,3 @@

this.maxChoices = options.maxChoices || Infinity;
this.multiple = options.multiple || false;
this.initial = options.initial || 0;

@@ -45,37 +47,31 @@ this.longest = 0;

async toChoices(choices, parent) {
if (typeof choices === 'function') choices = await choices.call(this);
async toChoices(value, parent) {
let choices = [];
let index = 0;
if (Array.isArray(choices)) {
for (let i = 0; i < choices.length; i++) {
if (typeof choices[i] === 'function') {
choices[i] = await choices[i](this);
}
}
}
let toChoices = async(items, parent) => {
if (typeof items === 'function') items = await items.call(this);
if (items instanceof Promise) items = await items;
if (isObject(choices)) {
choices = toArray(choices);
}
for (let i = 0; i < items.length; i++) {
let choice = items[i] = await this.toChoice(items[i], index++, parent);
choices.push(choice);
let list = await Promise.all(choices);
for (let i = 0; i < list.length; i++) {
let item = list[i];
item = await this.toChoice(item, i, parent);
if (item.choices) {
item.choices = await this.toChoices(item.choices, item);
if (choice.choices) {
await toChoices(choice.choices, choice);
}
}
list[i] = item;
}
return choices;
};
return list;
return toChoices(value, parent);
}
async toChoice(ele, i, parent) {
if (typeof ele === 'function') ele = await ele.call(this, this);
if (ele instanceof Promise) ele = await ele;
if (typeof ele === 'function') ele = await ele.call(this);
if (typeof ele === 'string') ele = { name: ele };
if (ele.normalized === true) return ele;
ele.normalized = true;
ele.role = ele.role || 'option';
if (typeof ele.disabled === 'string') {

@@ -86,9 +82,15 @@ ele.hint = ele.disabled;

if (ele.disabled === true && !ele.hint) {
if (ele.disabled === true && ele.hint == null) {
ele.hint = '(disabled)';
}
if (ele.role === 'separator') {
ele.disabled = true;
ele.indicator = [ele.indicator, ' '].find(v => v != null);
ele.message = ele.message || this.symbols.line.repeat(5);
}
if (ele.index != null) return ele;
ele.name = ele.name || ele.key || ele.title || ele.value || ele.message;
ele.message = ele.message || ele.name;
ele.message = ele.message || ele.name || '';
ele.value = ele.value || ele.name;

@@ -101,4 +103,6 @@

ele.parent = parent;
ele.level = parent ? parent.level + 1 : 1;
ele.indent = parent ? parent.indent + ' ' : (ele.indent || '');
ele.enabled = !!(this.multiple && !ele.disabled && (ele.enabled || this.isSelected(ele)));
ele.path = parent ? parent.path + '.' + ele.name : ele.name;
ele.enabled = !!(this.multiple && !this.skipChoice(ele) && (ele.enabled || this.isSelected(ele)));

@@ -109,3 +113,6 @@ if (typeof ele.initial === 'function') {

this.longest = Math.max(this.longest, ele.message.length);
if (!this.skipChoice(ele)) {
this.longest = Math.max(this.longest, colors.unstyle(ele.message).length);
}
let init = { ...ele };

@@ -127,4 +134,8 @@

indent(choice) {
return choice.level > 1 ? ' '.repeat(choice.level - 1) : '';
}
dispatch(s, key) {
if (this.options.multiple && this[key.name]) {
if (this.multiple && this[key.name]) {
return this[key.name]();

@@ -143,3 +154,3 @@ }

space() {
if (!this.options.multiple) return this.alert();
if (!this.multiple) return this.alert();
this.toggle(this.focused);

@@ -177,3 +188,3 @@ return this.render();

while (parent) {
let choices = parent.choices.filter(ch => ch.disabled);
let choices = parent.choices.filter(ch => this.skipChoice(ch));
parent.enabled = choices.every(ch => ch.enabled);

@@ -418,5 +429,18 @@ parent = parent.parent;

}
let result = this.options.multiple ? this.selected : this.focused;
if (result === void 0) return this.alert();
this.value = Array.isArray(result) ? result.map(ch => ch.name) : result.name;
let multi = this.multiple === true;
let value = multi ? this.selected : this.focused;
if (value === void 0) {
return this.alert();
}
if (multi && this.choices.some(ch => ch.choices)) {
this.value = {};
for (let choice of value) set(this.value, choice.path, choice.value);
} else if (multi) {
this.value = value.map(ch => ch.name);
} else {
this.value = value.name;
}
return super.submit();

@@ -479,3 +503,3 @@ }

let choice = this.choices[this.index];
if (this.state.submitted && this.options.multiple !== true) {
if (this.state.submitted && this.multiple !== true) {
choice.enabled = true;

@@ -487,40 +511,6 @@ }

get selected() {
return this.options.multiple ? this.enabled : this.focused;
return this.multiple ? this.enabled : this.focused;
}
}
function toArray(choices) {
let i = 0;
const toChoices = (list, parent) => {
if (Array.isArray(list)) {
return list.map(ch => toChoice(ch, i++, parent));
}
let result = [];
for (let name of Object.keys(list)) {
if (typeof list[name] === 'string') {
result.push(list);
continue;
}
let ele = list[name];
if (isObject(ele) && !hasChoices(ele)) {
result.push(toChoice({ name, ...ele }, i++, parent));
continue;
}
let group = toChoice(name, i++, parent);
result.push(group);
if (ele && typeof ele === 'object') {
group.choices = toChoices(ele, group);
group.choices.forEach(c => result.push(c));
} else {
group[name] = ele;
}
}
return result;
};
return toChoices(choices);
}
function reset(prompt, choices) {

@@ -539,28 +529,2 @@ for (let choice of choices) {

function hasChoices(obj) {
let hasArray = false;
let i = 0;
for (let key of Object.keys(obj)) {
i++;
if (Array.isArray(obj[key])) {
hasArray = true;
break;
}
if (isObject(obj[key])) {
hasArray = hasChoices(obj[key]);
break;
}
hasArray = false;
}
return i === 1 && hasArray;
}
function toChoice(choice, i, parent) {
if (typeof choice === 'string') choice = { name: choice, message: choice };
choice.index = i;
choice.parent = parent;
choice.indent = parent ? parent.indent + ' ' : (choice.indent || '');
return choice;
}
module.exports = ArrayPrompt;
{
"name": "enquirer",
"description": "Stylish, intuitive and user-friendly prompt system. Fast and lightweight enough for small projects, powerful and extensible enough for the most advanced use cases.",
"version": "2.0.1",
"version": "2.0.2",
"homepage": "https://github.com/enquirer/enquirer",

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

"toc": false,
"layout": "common-minimal",
"layout": false,
"tasks": [

@@ -85,0 +85,0 @@ "readme"

@@ -1,9 +0,18 @@

# enquirer [![NPM version](https://img.shields.io/npm/v/enquirer.svg?style=flat)](https://www.npmjs.com/package/enquirer) [![NPM monthly downloads](https://img.shields.io/npm/dm/enquirer.svg?style=flat)](https://npmjs.org/package/enquirer) [![NPM total downloads](https://img.shields.io/npm/dt/enquirer.svg?style=flat)](https://npmjs.org/package/enquirer) [![Linux Build Status](https://img.shields.io/travis/enquirer/enquirer.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/enquirer)
<h1 align="center">Enquirer</h1>
> Stylish, intuitive and user-friendly prompt system. Fast and lightweight enough for small projects, powerful and extensible enough for the most advanced use cases.
<p align="center">
<a href="https://npmjs.org/package/enquirer">
<img src="https://img.shields.io/npm/v/enquirer.svg" alt="version">
</a>
<a href="https://travis-ci.org/enquirer/enquirer">
<img src="https://img.shields.io/travis/enquirer/enquirer.svg" alt="travis">
</a>
<a href="https://npmjs.org/package/enquirer">
<img src="https://img.shields.io/npm/dm/enquirer.svg" alt="downloads">
</a>
<a href="https://packagephobia.now.sh/result?p=enquirer">
<img src="https://packagephobia.now.sh/badge?p=enquirer" alt="install size">
</a>
</p>
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
<h1 align="center">Enquirer</h1>
<br>

@@ -38,12 +47,2 @@ <br>

## ❯ Beta release!!!
We're extremely excited to announce that we've published Enquirer 2.0.0 as a beta release to [npm](https://www.npmjs.com/package/enquirer/v/beta). To use the beta version see the [installation instructions below](#-install).
This documentation is for the beta, which means we're still working on documenting everything, creating [examples](./examples), and having fun writing [recipes](./recipes) to demonstrate how [prompts](#prompt-api) can be extended and customized. If you'd like to contribute to any of these, please feel free to open an [issue](https://github.com/enquirer/enquirer/issues/new) for discussion or [pull request](https://github.com/enquirer/enquirer/pulls) with your changes. We are also looking for technical writers to help with writing more detailed user and developer documentation, tutorials, and blog posts about Enquirer 2 and all of the awesome features that are available.
<br>
<hr>
<br>
## ❯ Install

@@ -397,5 +396,1 @@

Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 04, 2018._
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