Socket
Socket
Sign inDemoInstall

enquirer

Package Overview
Dependencies
1
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.6 to 2.0.7

lib/prompts/multiscale.js

1

index.js

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

* Create an instance of `Enquirer`.
*
* ```js

@@ -11,0 +12,0 @@ * const Enquirer = require('enquirer');

3

lib/prompt.js

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

this.render = (this.options.render || this.render).bind(this);
this.term = process.env.TERM_PROGRAM;
this.setMaxListeners(0);

@@ -117,3 +118,3 @@ }

if (result !== true) {
let error = this.symbols.pointer + ' ' + result.trim();
let error = this.symbols.pointer + ' ' + (typeof result === 'string' ? result.trim() : 'Invalid input');
this.state.error = '\n' + this.styles.danger(error);

@@ -120,0 +121,0 @@ this.state.submitted = false;

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

define('Invisible', () => require('./invisible'));
define('MultiScale', () => require('./multiscale'));
define('List', () => require('./list'));

@@ -18,0 +19,0 @@ define('MultiSelect', () => require('./multiselect'));

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

this.emptyError = options.emptyError || 'No items were selected';
this.pos = { h: 0, get v() { return this.index; } };
this.term = process.env.TERM_PROGRAM;

@@ -76,3 +75,2 @@

await this.onChoice(item, i);
let focused = this.index === i;

@@ -87,4 +85,2 @@ let isHyper = this.term === 'Hyper';

let num = i + 1 + '.';
let values = [0, 1, 2, 3, 4];
let color = focused ? this.styles.heading : this.styles.noop;

@@ -94,3 +90,3 @@ let msg = await this.resolve(item.message, this.state, item, i);

let scale = indent + item.scale.map((e, i) => dot(i === item.scaleIdx)).join(ln);
let val = i => i === item.scaleIdx ? color(values[i]) : values[i];
let val = i => i === item.scaleIdx ? color(i) : i;
let next = indent + item.scale.map((e, i) => val(i)).join(sp);

@@ -97,0 +93,0 @@

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

exports.longest = (arr, prop) => {
return arr.reduce((a, v) => Math.max(a, prop ? v[prop].length : v.length), 0);
};
exports.hasColor = str => {

@@ -22,0 +26,0 @@ /* eslint-disable no-control-regex */

{
"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.6",
"version": "2.0.7",
"homepage": "https://github.com/enquirer/enquirer",

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

"scripts": {
"test": "mocha",
"test": "mocha && tsc -p ./test/types",
"cover": "nyc --reporter=text --reporter=html mocha"

@@ -33,2 +33,3 @@ },

"devDependencies": {
"@types/node": "^8",
"cli-spinners": "^1.3.1",

@@ -43,2 +44,3 @@ "data-store": "^3.1.0",

"time-require": "github:jonschlinkert/time-require",
"typescript": "^3.1.6",
"yosay": "^2.0.2"

@@ -45,0 +47,0 @@ },

@@ -19,3 +19,3 @@ <h1 align="center">Enquirer</h1>

<p align="center">
<b>Stylish CLI prompts that are user-friendly, intuitive and easy to create.</b></br>
<b>Stylish CLI prompts that are user-friendly, intuitive and easy to create.</b><br>
<sub>>_ Prompts should be more like conversations than inquisitions▌<sub>

@@ -33,8 +33,10 @@ </p>

Please consider starting or tweeting about this project to show your support. Thanks!
Created by [jonschlinkert](https://github.com/jonschlinkert) and [doowb](https://github.com/doowb), Enquirer is fast, easy to use, and lightweight enough for small projects, while also being powerful and customizable enough for the most advanced use cases.
* **Fast** - [Loads in ~4ms](#-performance) (that's about _3-4 times faster than a [single frame of a HD movie](http://www.endmemo.com/sconvert/framespersecondframespermillisecond.php) at 60fps_)
* **Lightweight** - Only [one dependency](https://github.com/doowb/ansi-colors).
* **Lightweight** - Only one dependency, the excellent [ansi-colors](https://github.com/doowb/ansi-colors) by [Brian Woodward](https://github.com/doowb).
* **Easy to implement** - Uses promises and async/await and sensible defaults to make prompts easy to create and implement.
* **Easy to use** - Thrill your users! Navigating around input and choices is a breeze. You can even create [quizzes](recipes/quiz.js), or [record](recipes/record.js) and [playback](recipes/play.js) keypresses to aid with tutorials and videos.
* **Easy to use** - Thrill your users with a better experience! Navigating around input and choices is a breeze. You can even create [quizzes](recipes/quiz.js), or [record](recipes/record.js) and [playback](recipes/play.js) keypresses to aid with tutorials and videos.
* **Intuitive** - Keypress combos are available to simplify usage.

@@ -49,4 +51,14 @@ * **Flexible** - All prompts can be used standalone or chained together.

_(If you like Enquirer, you might also like [micromatch](https://github.com/micromatch/micromatch), created by [Jon Schlinkert](https://github.com/jonschlinkert), author of Enquirer)_.
<br>
<p align="center">
<b>Ready to start making prompts your users will love?</b><br>
<img src="https://github.com/enquirer/enquirer/raw/master/media/heartbeat.gif" alt="Enquirer Select Prompt with heartbeat example" width="750">
</p>
<br>
<br>
## ❯ Getting started

@@ -58,3 +70,3 @@

* [Usage](#-usage)
* [Enquirer API](#-enquirer-api)
* [Enquirer](#-enquirer)
* [Built-in Prompts](#-prompts)

@@ -75,5 +87,9 @@ * [Custom Prompts](#-custom-prompts)

```sh
$ npm install --save enquirer
$ npm install enquirer
```
<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/npm-install.gif" alt="Install Enquirer with NPM" width="750">
</p>
_(Requires Node.js 8.6 or higher. Please let us know if you need support for an earlier version by creating an [issue](../../issues/new).)_

@@ -83,11 +99,2 @@

## ❯ Overview
### How does Enquirer work?
Enquirer is a [Node.js](https://nodejs.org/en/) library.
The main export is the `Enquirer` class.
<br>
## ❯ Usage

@@ -144,13 +151,75 @@

* Customizing symbols
* Customizing styles (palette)
* Customizing styles
* Links to recipes
* [ ] Customizing symbols
* [ ] Customizing styles (palette)
* [ ] Customizing rendered input
* [ ] Customizing returned values
* [ ] Question validation
* [ ] Choice validation
* [ ] Skipping questions
* [ ] Async choices
* [ ] Async loaders, spinners and other timers
* [ ] Links to recipes
<br>
## ❯ Enquirer API
## ❯ Enquirer
### [Enquirer](index.js#L19)
The main export of this library is the `Enquirer` class. You can add Enquirer to your JavaScript project with following line of code.
```js
const Enquirer = require('enquirer');
```
### How does Enquirer work?
**Enquirer is a prompt runner**
Enquirer has methods and features designed to simplify running multiple prompts.
```js
const { prompt } = require('enquirer');
const question = [
{
type: 'input',
name: 'username',
message: 'What is your username?'
},
{
type: 'password',
name: 'password',
message: 'What is your password?'
}
];
let answers = await prompt(question);
console.log(answers);
```
**Prompts control how values are rendered and returned**
Each individual prompt is a class with special features and functionality for rendering the types of values you want to show users in the terminal, and subsequently returning the types of values you need to use in your application.
**How can I customize prompts?**
Below in this guide you will find information about creating [custom prompts](#-custom-prompts). For now, we'll focus on how to customize an existing prompt.
All of the individual [prompt classes](#built-in-prompts) in this library are exposed as static properties on Enquirer. This allows them to be used directly (without using `enquirer.prompt()`.
Use this approach if you need to modify a prompt instance, or listen for events on the prompt.
**Example**
```js
const { Input } = require('enquirer');
const prompt = new Input({
name: 'username',
message: 'What is your username?'
});
let answer = await prompt.run();
console.log('Username:', answer);
```
### [Enquirer](index.js#L20)
Create an instance of `Enquirer`.

@@ -170,3 +239,3 @@

### [register](index.js#L41)
### [register](index.js#L42)

@@ -189,3 +258,3 @@ Register a custom prompt type.

### [prompt](index.js#L77)
### [prompt](index.js#L78)

@@ -213,3 +282,3 @@ Prompt function that takes a "question" object or array of question objects, and returns an object with responses from the user.

### [use](index.js#L150)
### [use](index.js#L151)

@@ -234,3 +303,3 @@ Use an enquirer plugin.

### [Enquirer#prompt](index.js#L211)
### [Enquirer#prompt](index.js#L212)

@@ -258,8 +327,17 @@ Prompt function that takes a "question" object or array of question objects, and returns an object with responses from the user.

* [Built-in prompts](#built-in-prompts)
* [Prompt Options](#options)
### Built-in prompts
* [Prompt](#prompt) - The base `Prompt` class used by other prompts
* [AutoComplete](#autocomplete-prompt)
* [Confirm](#confirm-prompt)
* [Form](#form-prompt)
* [hSelect](#hselect-prompt) (horizontal select)
* [hMultiSelect](#hmultiselect-prompt) (horizontal multiselect)
* [Input](#input-prompt)
* [Invisible](#invisible-prompt)
* [List](#list-prompt)
* [Multiselect](#multiselect-prompt)
* [MultiSelect](#multiselect-prompt)
* [Number](#number-prompt)

@@ -271,4 +349,15 @@ * [Password](#password-prompt)

* [Survey](#survey-prompt)
* `Text` (alias for [Input](#input-prompt))
* [Text](#input-prompt) (alias for the [Input prompt](#input-prompt))
### Prompt
The base `Prompt` class is used to create all other prompts.
```js
const { Prompt } = require('enquirer');
class MyCustomPrompt extends Prompt {}
```
See the documentation for [creating custom prompts](#-custom-prompts) to learn more about how this works.
### AutoComplete Prompt

@@ -279,13 +368,46 @@

<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/autocomplete-prompt.gif" alt="Enquirer Autocomplete Prompt" width="750">
<img src="https://github.com/enquirer/enquirer/raw/master/media/autocomplete-prompt.gif" alt="Enquirer AutoComplete Prompt" width="750">
</p>
**Example Usage**
```js
const question = {
type: 'autocomplete',
name: 'country',
message: 'Where to?',
limit: 5,
suggest(input, choices) {
return choices.filter(choice => choice.message.startsWith(input));
},
choices: [
'Afghanistan',
'Albania',
'Algeria',
'Andorra',
'Angola',
...
]
};
```
**AutoComplete Options**
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `highlight` | `function` | `dim` version of primary style | The color to use when "highlighting" characters in the list that match user input. |
| `multiple` | `boolean` | `false` | Allow multiple choices to be selected. |
| `suggest` | `function` | Greedy match, returns true if choice message contains input string. | Function that filters choices. Takes user input and a choices array, and returns a list of matching choices. |
**Related prompts**
* [select prompt](#select-prompt)
* [multiselect prompt](#multiselect-prompt)
* [survey prompt](#survey-prompt)
* [Select](#select-prompt)
* [MultiSelect](#multiselect-prompt)
* [Survey](#survey-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Confirm Prompt

@@ -301,8 +423,11 @@

* [input prompt](#input-prompt)
* [number prompt](#number-prompt)
* [password prompt](#password-prompt)
* [Input](#input-prompt)
* [Numeral](#numeral-prompt)
* [Password](#password-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Form Prompt

@@ -318,7 +443,48 @@

* [input prompt](#input-prompt)
* [survey prompt](#number-prompt)
* [Input](#input-prompt)
* [Survey](#survey-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### hSelect Prompt
The `hSelect` (Horizontal Select) allows the user to select from a horizontal list of choices.
<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/hselect-prompt.gif" alt="Enquirer Horizontal Select / hSelect Prompt" width="750">
</p>
**Related prompts**
* [Select](#select-prompt)
* [MultiSelect](#multiselect-prompt)
* [Hmultiselect](#hmultiselect-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### hMultiSelect Prompt
The `hMultiSelect` (Horizontal MultiSelect) allows the user to select multiple items from a horizontal list of choices.
<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/hmultiselect-prompt.gif" alt="Enquirer Horizontal MultiSelect / hMultiSelect Prompt" width="750">
</p>
**Related prompts**
* [Select](#select-prompt)
* [Hselect](#hselect-prompt)
* [MultiSelect](#multiselect-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Input Prompt

@@ -332,10 +498,42 @@

**Usage**
Usage with Enquirer.
```js
const { prompt } = require('enquirer');
const question = {
type: 'input',
name: 'username',
message: 'What is your username?'
};
let answers = await prompt(question);
console.log('Username:', answers.username);
```
Usage as a standalone prompt. Use this approach if you need to modify the prompt instance, or listen for events on the prompt.
```js
const { Input } = require('enquirer');
const prompt = new Input({
name: 'username',
message: 'What is your username?'
});
let answer = await prompt.run();
console.log('Username:', answer);
```
**Related prompts**
* [confirm prompt](#confirm-prompt)
* [number prompt](#number-prompt)
* [password prompt](#password-prompt)
* [Confirm](#confirm-prompt)
* [Numeral](#numeral-prompt)
* [Password](#password-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Invisible Prompt

@@ -351,7 +549,10 @@

* [password prompt](#password-prompt)
* [input prompt](#input-prompt)
* [Password](#password-prompt)
* [Input](#input-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### List Prompt

@@ -367,13 +568,35 @@

* [sort prompt](#sort-prompt)
* [select prompt](#select-prompt)
* [Sort](#sort-prompt)
* [Select](#select-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
### Multiselect Prompt
<br>
<br>
### MultiScale Prompt
Prompt that allows the user to quickly provide feedback using a [Likert Scale](https://en.wikipedia.org/wiki/Likert_scale).
<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/multiscale-prompt.gif" alt="Enquirer MultiScale Prompt" width="750">
</p>
**Related prompts**
* [AutoComplete](#autocomplete-prompt)
* [Select](#select-prompt)
* [Survey](#survey-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### MultiSelect Prompt
Prompt that allows the user to select multiple items from a list of options.
<p align="center">
<img src="https://github.com/enquirer/enquirer/raw/master/media/multiselect-prompt.gif" alt="Enquirer Multiselect Prompt" width="750">
<img src="https://github.com/enquirer/enquirer/raw/master/media/multiselect-prompt.gif" alt="Enquirer MultiSelect Prompt" width="750">
</p>

@@ -383,7 +606,10 @@

* [select prompt](#select-prompt)
* [autocomplete prompt](#autocomplete-prompt)
* [Select](#select-prompt)
* [AutoComplete](#autocomplete-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Numeral Prompt

@@ -399,7 +625,10 @@

* [input prompt](#input-prompt)
* [confirm prompt](#confirm-prompt)
* [Input](#input-prompt)
* [Confirm](#confirm-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Password Prompt

@@ -415,7 +644,10 @@

* [input prompt](#input-prompt)
* [invisible prompt](#invisible-prompt)
* [Input](#input-prompt)
* [Invisible](#invisible-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Select Prompt

@@ -431,7 +663,10 @@

* [autocomplete prompt](#autocomplete-prompt)
* [multiselect prompt](#multiselect-prompt)
* [AutoComplete](#autocomplete-prompt)
* [MultiSelect](#multiselect-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Snippet Prompt

@@ -447,7 +682,10 @@

* [survey prompt](#survey-prompt)
* [autocomplete prompt](#autocomplete-prompt)
* [Survey](#survey-prompt)
* [AutoComplete](#autocomplete-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Sort Prompt

@@ -467,7 +705,10 @@

* [list prompt](#list-prompt)
* [select prompt](#select-prompt)
* [List](#list-prompt)
* [Select](#select-prompt)
**↑ back to:** [Getting Started](#-getting-started) · [Prompts](#-prompts)
<br>
<br>
### Survey Prompt

@@ -483,5 +724,9 @@

* [snippet prompt](#snippet-prompt)
* [select prompt](#select-prompt)
* [MultiScale](#multiscale-prompt)
* [Snippet](#snippet-prompt)
* [Select](#select-prompt)
<br>
<br>
## ❯ Types

@@ -546,9 +791,32 @@

Array prompts support the `choices` option, which is the array of choices you want to allow the user to select from. Choices may be defined as strings or objects.
Array prompts support the `choices` option, which is the array of choices users will be able to select from when rendered in the terminal.
**Choice objects**
**Type**: `string|object`
Choices are normalized to the following interface:
**Example**
```js
const { prompt } = require('enquirer');
const questions = [{
type: 'select',
name: 'color',
message: 'Favorite color?',
initial: 1,
choices: [
{ name: 'red', message: 'Red', value: '#ff0000' }, //<= choice object
{ name: 'green', message: 'Green', value: '#00ff00' }, //<= choice object
{ name: 'blue', message: 'Blue', value: '#0000ff' } //<= choice object
]
}];
let answers = await prompt(questions);
console.log('Answer:', answers.color);
```
#### Defining choices
Whether defined as a string or object, choices are normalized to the following interface:
```js
{

@@ -563,12 +831,36 @@ name: string;

**Choice properties**
**Example**
```js
const question = {
name: 'fruit',
message: 'Favorite fruit?'
choices: ['Apple', 'Orange', 'Raspberry']
};
// Normalizes to the following when the prompt is run:
//
// const question = {
// name: 'fruit',
// message: 'Favorite fruit?'
// choices: [
// { name: 'Apple', message: 'Apple', value: 'Apple' },
// { name: 'Orange', message: 'Orange', value: 'Orange' },
// { name: 'Raspberry', message: 'Raspberry', value: 'Raspberry' }
// ]
// }
```
#### Choice properties
The following properties are supported on `choice` objects.
| **Option** | **Type** | **Description** |
| --- | --- | --- |
| `name` | `string` | The unique key to identify a choice |
| `message` | `string` | The message to display in the terminal. `name` is used when this is undefined. |
| `value` | `string` | Value to associate with the choice. Useful for creating key-value pairs from user choices. `name` is used when this is undefined. |
| `choices` | `array` | Array of "child" choices. |
| `hint` | `string` | Help message to display next to a choice. |
| `role` | `string` | Determines how the choice will be displayed. Currently the only role supported is `separator`. Additional roles may be added in the future (like `heading`, etc). Please create a [feature request] |
| `name` | `string` | The unique key to identify a choice |
| `message` | `string` | The message to display in the terminal. `name` is used when this is undefined. |
| `value` | `string` | Value to associate with the choice. Useful for creating key-value pairs from user choices. `name` is used when this is undefined. |
| `choices` | `array` | Array of "child" choices. |
| `hint` | `string` | Help message to display next to a choice. |
| `role` | `string` | Determines how the choice will be displayed. Currently the only role supported is `separator`. Additional roles may be added in the future (like `heading`, etc). Please create a [feature request] |
| `enabled` | `boolean` | Enabled a choice by default. This is only supported when `options.multiple` is true or on prompts that support multiple choices, like [MultiSelect](#-multiselect). |

@@ -578,31 +870,9 @@ | `disabled` | `boolean\|string` | Disable a choice so that it cannot be selected. This value may either be `true`, `false`, or a message to display. |

**Example usage**
```js
const { prompt } = require('enquirer');
const question = {
type: 'select',
name: 'color',
message: 'Favorite color?',
initial: 1,
choices: [
{ name: 'red', message: 'Red', value: '#ff0000' },
{ name: 'green', message: 'Green', value: '#00ff00' },
{ name: 'blue', message: 'Blue', value: '#0000ff' }
]
};
prompt(question)
.then(answer => console.log('Answer:', answer))
.catch(console.error);
```
#### Related prompts
* [autocomplete prompt](#autocomplete-prompt)
* [form prompt](#form-prompt)
* [multiselect prompt](#multiselect-prompt)
* [select prompt](#select-prompt)
* [survey prompt](#survey-prompt)
* [AutoComplete](#autocomplete-prompt)
* [Form](#form-prompt)
* [MultiSelect](#multiselect-prompt)
* [Select](#select-prompt)
* [Survey](#survey-prompt)

@@ -659,2 +929,16 @@ ### BooleanPrompt

Custom prompts may be used directly by creating an instance of your custom prompt class.
```js
const prompt = new HaiKarate({
message: 'How many sprays do you want?',
initial: 10
});
prompt.run()
.then(answer => console.log('Sprays:', answer))
.catch(console.error);
```
To register a custom prompt, you must first instantiate `Enquirer`.

@@ -879,2 +1163,2 @@

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
Released under the [MIT License](LICENSE).
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