Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prompts

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompts - npm Package Compare versions

Comparing version 0.1.14 to 1.0.0

103

dist/elements/autocomplete.js

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

const util = require('../util');
const color = require('kleur');

@@ -14,5 +13,12 @@ const Prompt = require('./prompt');

// Get value, with fallback to title
var _require2 = require('../util');
const style = _require2.style,
clear = _require2.clear,
figures = _require2.figures,
strip = _require2.strip;
const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]);
const getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]);

@@ -30,2 +36,4 @@ /**

* @param {String} [opts.initial] Index of the default value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -39,11 +47,13 @@ class AutocompletePrompt extends Prompt {

this.initial = opts.initial;
this.cursor = opts.initial || opts.cursor || 0;
this.fallback = opts.fallback || opts.initial !== void 0 ? `${util.figures.pointerSmall} ${getVal(this.choices, this.initial)}` : `${util.figures.pointerSmall} no matches found`;
this.select = opts.initial || opts.cursor || 0;
this.fallback = opts.fallback || opts.initial !== void 0 ? `${figures.pointerSmall} ${getTitle(this.choices, this.initial)}` : `${figures.pointerSmall} no matches found`;
this.suggestions = [];
this.input = '';
this.limit = opts.limit || 10;
this.transform = util.style.render(opts.style);
this.cursor = 0;
this.transform = style.render(opts.style);
this.scale = this.transform.scale;
this.render = this.render.bind(this);
this.complete = this.complete.bind(this);
this.clear = util.clear('');
this.clear = clear('');
this.complete(this.render);

@@ -53,4 +63,4 @@ this.render(true);

moveCursor(i) {
this.cursor = i;
moveSelect(i) {
this.select = i;
if (this.suggestions.length > 0) this.value = getVal(this.suggestions, i);else this.value = this.initial !== void 0 ? getVal(this.choices, this.initial) : null;

@@ -70,3 +80,3 @@ this.fire();

_this.suggestions = suggestions.slice(0, _this.limit).map(function (s) {
return util.strip(s);
return strip(s);
});

@@ -76,3 +86,3 @@ _this.completing = false;

const l = Math.max(suggestions.length - 1, 0);
_this.moveCursor(Math.min(l, _this.cursor));
_this.moveSelect(Math.min(l, _this.select));

@@ -86,3 +96,3 @@ cb && cb();

this.complete(() => {
this.moveCursor(this.initial !== void 0 ? this.initial : 0);
this.moveSelect(this.initial !== void 0 ? this.initial : 0);
this.render();

@@ -111,3 +121,6 @@ });

_(c, key) {
this.input += c;
let s1 = this.input.slice(0, this.cursor);
let s2 = this.input.slice(this.cursor);
this.cursor = this.cursor + 1;
this.input = `${s1}${c}${s2}`;
this.complete(this.render);

@@ -119,4 +132,7 @@ this.render();

if (this.input.length === 0) return this.bell();
this.input = this.input.slice(0, -1);
let s1 = this.input.slice(0, this.cursor - 1);
let s2 = this.input.slice(this.cursor);
this.input = `${s1}${s2}`;
this.complete(this.render);
this.cursor = this.cursor - 1;
this.render();

@@ -126,3 +142,3 @@ }

first() {
this.moveCursor(0);
this.moveSelect(0);
this.render();

@@ -132,3 +148,3 @@ }

last() {
this.moveCursor(this.suggestions.length - 1);
this.moveSelect(this.suggestions.length - 1);
this.render();

@@ -138,4 +154,4 @@ }

up() {
if (this.cursor <= 0) return this.bell();
this.moveCursor(this.cursor - 1);
if (this.select <= 0) return this.bell();
this.moveSelect(this.select - 1);
this.render();

@@ -145,4 +161,4 @@ }

down() {
if (this.cursor >= this.suggestions.length - 1) return this.bell();
this.moveCursor(this.cursor + 1);
if (this.select >= this.suggestions.length - 1) return this.bell();
this.moveSelect(this.select + 1);
this.render();

@@ -152,19 +168,52 @@ }

next() {
this.moveCursor((this.cursor + 1) % this.suggestions.length);
this.moveSelect((this.select + 1) % this.suggestions.length);
this.render();
}
render(first) {
if (first) this.out.write(cursor.hide);
left() {
if (this.cursor <= 0) return this.bell();
this.cursor = this.cursor - 1;
this.render();
}
let prompt = [util.style.symbol(this.done, this.aborted), this.msg, util.style.delimiter(this.completing), this.done && this.suggestions[this.cursor] ? this.suggestions[this.cursor].title : this.transform.render(this.input)].join(' ');
right() {
if (this.cursor * this.scale >= this.rendered.length) return this.bell();
this.cursor = this.cursor + 1;
this.render();
}
if (!this.done) {
let suggestions = this.suggestions.map((item, i) => `\n${i === this.cursor ? color.cyan(item.title) : item.title}`);
render() {
if (this.lineCount) this.out.write(cursor.down(this.lineCount));
prompt += suggestions.length ? suggestions.reduce((acc, line) => acc + line, '') : `\n${color.gray(this.fallback)}`;
let prompt = `${style.symbol(this.done, this.aborted)} ${this.msg} ${style.delimiter(this.completing)} `;
let length = strip(prompt).length;
if (this.done && this.suggestions[this.select]) {
prompt += `${this.suggestions[this.select].title}`;
} else {
this.rendered = `${this.transform.render(this.input)}`;
length += this.rendered.length;
prompt += this.rendered;
}
if (!this.done) {
this.lineCount = this.suggestions.length;
let suggestions = this.suggestions.reduce((acc, item, i) => acc += `\n${i === this.select ? color.cyan(item.title) : item.title}`, '');
if (suggestions) {
prompt += suggestions;
} else {
prompt += `\n${color.gray(this.fallback)}`;
this.lineCount += 1;
}
}
this.out.write(this.clear + prompt);
this.clear = util.clear(prompt);
this.clear = clear(prompt);
if (this.lineCount && !this.done) {
let pos = cursor.up(this.lineCount);
pos += cursor.left + cursor.to(length);
pos += cursor.move(-this.rendered.length + this.cursor * this.scale);
this.out.write(pos);
}
}

@@ -171,0 +220,0 @@ }

@@ -21,2 +21,4 @@ 'use strict';

* @param {Boolean} [opts.initial] Default value (true/false)
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -23,0 +25,0 @@

@@ -24,2 +24,4 @@ 'use strict';

* @param {Number} [opts.max] Max choices
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -26,0 +28,0 @@

'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const color = require('kleur');

@@ -14,3 +16,5 @@ const Prompt = require('./prompt');

const style = _require2.style,
clear = _require2.clear;
clear = _require2.clear,
figures = _require2.figures,
strip = _require2.strip;

@@ -37,2 +41,5 @@

* @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
* @param {Function} [opts.validate] Validate function
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -50,4 +57,7 @@ class NumberPrompt extends Prompt {

this.max = isDef(opts.max) ? opts.max : Infinity;
this.value = '';
this.typed = '';
this.errorMsg = `Please Enter A Valid Value`;
this.validator = opts.validate || (() => true);
this.color = `cyan`;
this.value = ``;
this.typed = ``;
this.lastHit = 0;

@@ -61,3 +71,3 @@ this.render();

this.rendered = color.gray(this.transform.render(`${this.initial}`));
this._value = '';
this._value = ``;
} else {

@@ -80,8 +90,8 @@ this.placeholder = false;

valid(c) {
return c === '-' || c === '.' && this.float || isNumber.test(c);
return c === `-` || c === `.` && this.float || isNumber.test(c);
}
reset() {
this.typed = '';
this.value = '';
this.typed = ``;
this.value = ``;
this.fire();

@@ -93,25 +103,52 @@ this.render();

let x = this.value;
this.value = x !== '' ? x : this.initial;
this.value = x !== `` ? x : this.initial;
this.done = this.aborted = true;
this.error = false;
this.fire();
this.render();
this.out.write('\n');
this.out.write(`\n`);
this.close();
}
validate() {
var _this = this;
return _asyncToGenerator(function* () {
let valid = yield _this.validator(_this.value);
if (typeof valid === `string`) {
_this.errorMsg = valid;
valid = false;
}
_this.error = !valid;
})();
}
submit() {
let x = this.value;
this.value = x !== '' ? x : this.initial;
this.done = true;
this.aborted = false;
this.fire();
this.render();
this.out.write('\n');
this.close();
var _this2 = this;
return _asyncToGenerator(function* () {
yield _this2.validate();
if (_this2.error) {
_this2.color = `red`;
_this2.fire();
_this2.render();
return;
}
let x = _this2.value;
_this2.value = x !== `` ? x : _this2.initial;
_this2.done = true;
_this2.aborted = false;
_this2.error = false;
_this2.fire();
_this2.render();
_this2.out.write(`\n`);
_this2.close();
})();
}
up() {
this.typed = '';
this.typed = ``;
if (this.value >= this.max) return this.bell();
this.value += this.inc;
this.color = `cyan`;
this.fire();

@@ -122,5 +159,6 @@ this.render();

down() {
this.typed = '';
this.typed = ``;
if (this.value <= this.min) return this.bell();
this.value -= this.inc;
this.color = `cyan`;
this.fire();

@@ -133,3 +171,4 @@ this.render();

if (val.length === 0) return this.bell();
this.value = this.parse(val = val.slice(0, -1)) || '';
this.value = this.parse(val = val.slice(0, -1)) || ``;
this.color = `cyan`;
this.fire();

@@ -149,7 +188,8 @@ this.render();

const now = Date.now();
if (now - this.lastHit > 1000) this.typed = ''; // 1s elapsed
if (now - this.lastHit > 1000) this.typed = ``; // 1s elapsed
this.typed += c;
this.lastHit = now;
this.color = `cyan`;
if (c === '.') return this.fire();
if (c === `.`) return this.fire();

@@ -164,4 +204,22 @@ this.value = Math.min(this.parse(this.typed), this.max);

render() {
let clear = erase.line + (this.lines ? erase.down(this.lines) : ``) + cursor.to(0);
this.lines = 0;
let error = ``;
if (this.error) {
let lines = this.errorMsg.split(`\n`);
error += lines.reduce((a, l, i) => a += `\n${i ? ` ` : figures.pointerSmall} ${color.red.italic(l)}`, ``);
this.lines = lines.length;
}
let underline = !this.done || !this.done && !this.placeholder;
this.out.write(erase.line + cursor.to(0) + [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), underline ? color.cyan.underline(this.rendered) : this.rendered].join(' '));
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), underline ? color[this.color].underline(this.rendered) : this.rendered].join(` `);
let position = ``;
if (this.lines) {
position += cursor.up(this.lines);
position += cursor.left + cursor.to(strip(prompt).length);
}
this.out.write(clear + prompt + error + position);
}

@@ -168,0 +226,0 @@ }

@@ -18,2 +18,4 @@ 'use strict';

* Base prompt skeleton
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -20,0 +22,0 @@

@@ -24,2 +24,4 @@ 'use strict';

* @param {Number} [opts.initial] Index of default value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -26,0 +28,0 @@

'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const color = require('kleur');

@@ -13,3 +15,5 @@ const Prompt = require('./prompt');

const style = _require2.style,
clear = _require2.clear;
clear = _require2.clear,
strip = _require2.strip,
figures = _require2.figures;

@@ -22,2 +26,5 @@ /**

* @param {String} [opts.initial] Default value
* @param {Function} [opts.validate] Validate function
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -31,6 +38,8 @@

this.msg = opts.message;
this.initial = opts.initial || '';
this.value = '';
this.initial = opts.initial || ``;
this.validator = opts.validate || (() => true);
this.value = ``;
this.errorMsg = `Please Enter A Valid Value`;
this.cursor = Number(!!this.initial);
this.clear = clear('');
this.clear = clear(``);
this.render();

@@ -56,3 +65,4 @@ }

reset() {
this.value = '';
this.value = ``;
this.cursor = Number(!!this.initial);
this.fire();

@@ -65,2 +75,4 @@ this.render();

this.done = this.aborted = true;
this.error = false;
this.red = false;
this.fire();

@@ -72,10 +84,34 @@ this.render();

validate() {
var _this = this;
return _asyncToGenerator(function* () {
let valid = yield _this.validator(_this.value);
if (typeof valid === `string`) {
_this.errorMsg = valid;
valid = false;
}
_this.error = !valid;
})();
}
submit() {
this.value = this.value || this.initial;
this.done = true;
this.aborted = false;
this.fire();
this.render();
this.out.write('\n');
this.close();
var _this2 = this;
return _asyncToGenerator(function* () {
_this2.value = _this2.value || _this2.initial;
yield _this2.validate();
if (_this2.error) {
_this2.red = true;
_this2.fire();
_this2.render();
return;
}
_this2.done = true;
_this2.aborted = false;
_this2.fire();
_this2.render();
_this2.out.write('\n');
_this2.close();
})();
}

@@ -101,2 +137,3 @@

this.value = `${s1}${c}${s2}`;
this.red = false;
if (this.placeholder) this.cursor = 0;

@@ -111,2 +148,3 @@ this.render();

this.value = `${s1}${s2}`;
this.red = false;
this.moveCursor(-1);

@@ -139,8 +177,23 @@ this.render();

render() {
const prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.rendered].join(' ');
let erase = (this.lines ? cursor.down(this.lines) : ``) + this.clear;
this.lines = 0;
this.out.write(this.clear + prompt);
this.out.write(cursor.move(this.placeholder ? -this.initial.length * this.scale : -this.rendered.length + this.cursor * this.scale));
let prompt = [style.symbol(this.done, this.aborted), color.bold(this.msg), style.delimiter(this.done), this.red ? color.red(this.rendered) : this.rendered].join(` `);
this.clear = clear(prompt);
let error = ``;
if (this.error) {
let lines = this.errorMsg.split(`\n`);
error += lines.reduce((a, l, i) => a += `\n${i ? ' ' : figures.pointerSmall} ${color.red.italic(l)}`, ``);
this.lines = lines.length;
}
let position = ``;
if (this.lines) {
position += cursor.up(this.lines);
position += cursor.left + cursor.to(strip(prompt).length);
}
position += cursor.move(this.placeholder ? -this.initial.length * this.scale : -this.rendered.length + this.cursor * this.scale);
this.out.write(erase + prompt + error + position);
this.clear = clear(prompt + error);
}

@@ -147,0 +200,0 @@ }

@@ -23,2 +23,4 @@ 'use strict';

* @param {String} [opts.inactive='off'] Inactive label
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -25,0 +27,0 @@

@@ -35,5 +35,5 @@ 'use strict';

// if property is a function, invoke it unless it's ignored
// if property is a function, invoke it unless it's a special function
for (let key in question) {
if (ignore.includes(key)) continue;
if (passOn.includes(key)) continue;
let value = question[key];

@@ -97,3 +97,3 @@ question[key] = typeof value === 'function' ? yield value(answer, _extends({}, answers), question) : value;

const ignore = ['suggest', 'format', 'onState'];
const passOn = ['suggest', 'format', 'onState', 'validate'];
const noop = () => {};

@@ -100,0 +100,0 @@

@@ -24,2 +24,5 @@ 'use strict';

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -34,4 +37,6 @@ */

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input
*
*/

@@ -48,2 +53,5 @@ $.password = args => {

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -67,2 +75,5 @@ */

* @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -77,2 +88,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -89,2 +102,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input, in form of an `Array`

@@ -106,2 +121,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -118,2 +135,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -131,2 +150,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -155,2 +176,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -157,0 +180,0 @@ */

'use strict';
const util = require('../util');
const color = require('kleur');
const Prompt = require('./prompt');
const { cursor } = require('sisteransi');
const { style, clear, figures, strip } = require('../util');
// Get value, with fallback to title
const getVal = (arr, i) => arr[i] && (arr[i].value || arr[i].title || arr[i]);
const getTitle = (arr, i) => arr[i] && (arr[i].title || arr[i].value || arr[i]);

@@ -22,2 +22,4 @@ /**

* @param {String} [opts.initial] Index of the default value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -31,11 +33,15 @@ class AutocompletePrompt extends Prompt {

this.initial = opts.initial;
this.cursor = opts.initial || opts.cursor || 0;
this.fallback = opts.fallback || opts.initial !== void 0 ? `${util.figures.pointerSmall} ${getVal(this.choices, this.initial)}` : `${util.figures.pointerSmall} no matches found`;
this.select = opts.initial || opts.cursor || 0;
this.fallback = opts.fallback || opts.initial !== void 0 ?
`${figures.pointerSmall} ${getTitle(this.choices, this.initial)}` :
`${figures.pointerSmall} no matches found`;
this.suggestions = [];
this.input = '';
this.limit = opts.limit || 10;
this.transform = util.style.render(opts.style);
this.cursor = 0;
this.transform = style.render(opts.style);
this.scale = this.transform.scale;
this.render = this.render.bind(this);
this.complete = this.complete.bind(this);
this.clear = util.clear('');
this.clear = clear('');
this.complete(this.render);

@@ -45,4 +51,4 @@ this.render(true);

moveCursor(i) {
this.cursor = i;
moveSelect(i) {
this.select = i;
if (this.suggestions.length > 0) this.value = getVal(this.suggestions, i);

@@ -59,7 +65,7 @@ else this.value = this.initial !== void 0 ? getVal(this.choices, this.initial) : null;

this.suggestions = suggestions.slice(0, this.limit).map(s => util.strip(s));
this.suggestions = suggestions.slice(0, this.limit).map(s => strip(s));
this.completing = false;
const l = Math.max(suggestions.length - 1, 0);
this.moveCursor(Math.min(l, this.cursor));
this.moveSelect(Math.min(l, this.select));

@@ -72,3 +78,3 @@ cb && cb();

this.complete(() => {
this.moveCursor(this.initial !== void 0 ? this.initial : 0);
this.moveSelect(this.initial !== void 0 ? this.initial : 0);
this.render();

@@ -97,3 +103,6 @@ });

_(c, key) {
this.input += c;
let s1 = this.input.slice(0, this.cursor);
let s2 = this.input.slice(this.cursor);
this.cursor = this.cursor+1;
this.input = `${s1}${c}${s2}`;
this.complete(this.render);

@@ -105,4 +114,7 @@ this.render();

if (this.input.length === 0) return this.bell();
this.input = this.input.slice(0, -1);
let s1 = this.input.slice(0, this.cursor-1);
let s2 = this.input.slice(this.cursor);
this.input = `${s1}${s2}`;
this.complete(this.render);
this.cursor = this.cursor-1;
this.render();

@@ -112,3 +124,3 @@ }

first() {
this.moveCursor(0);
this.moveSelect(0);
this.render();

@@ -118,3 +130,3 @@ }

last() {
this.moveCursor(this.suggestions.length - 1);
this.moveSelect(this.suggestions.length - 1);
this.render();

@@ -124,4 +136,4 @@ }

up() {
if (this.cursor <= 0) return this.bell();
this.moveCursor(this.cursor - 1);
if (this.select <= 0) return this.bell();
this.moveSelect(this.select - 1);
this.render();

@@ -131,4 +143,4 @@ }

down() {
if (this.cursor >= this.suggestions.length - 1) return this.bell();
this.moveCursor(this.cursor + 1);
if (this.select >= this.suggestions.length - 1) return this.bell();
this.moveSelect(this.select + 1);
this.render();

@@ -138,29 +150,53 @@ }

next() {
this.moveCursor((this.cursor + 1) % this.suggestions.length);
this.moveSelect((this.select + 1) % this.suggestions.length);
this.render();
}
render(first) {
if (first) this.out.write(cursor.hide);
left() {
if (this.cursor <= 0) return this.bell();
this.cursor = this.cursor-1;
this.render();
}
let prompt = [
util.style.symbol(this.done, this.aborted),
this.msg,
util.style.delimiter(this.completing),
this.done && this.suggestions[this.cursor]
? this.suggestions[this.cursor].title
: this.transform.render(this.input)
].join(' ');
right() {
if (this.cursor*this.scale >= this.rendered.length) return this.bell();
this.cursor = this.cursor+1;
this.render();
}
if (!this.done) {
let suggestions = this.suggestions.map((item, i) =>
`\n${i === this.cursor ? color.cyan(item.title) : item.title}`);
render() {
if (this.lineCount) this.out.write(cursor.down(this.lineCount));
prompt += suggestions.length ?
suggestions.reduce((acc, line) => acc+line, '') :
`\n${color.gray(this.fallback)}`;
let prompt = `${style.symbol(this.done, this.aborted)} ${this.msg} ${style.delimiter(this.completing)} `;
let length = strip(prompt).length;
if (this.done && this.suggestions[this.select]) {
prompt += `${this.suggestions[this.select].title}`;
} else {
this.rendered = `${this.transform.render(this.input)}`
length += this.rendered.length;
prompt += this.rendered;
}
if (!this.done) {
this.lineCount = this.suggestions.length;
let suggestions = this.suggestions.reduce((acc, item, i) =>
acc += `\n${i === this.select ? color.cyan(item.title) : item.title}`, '');
if (suggestions) {
prompt += suggestions;
} else {
prompt += `\n${color.gray(this.fallback)}`;
this.lineCount += 1;
}
}
this.out.write(this.clear + prompt);
this.clear = util.clear(prompt);
this.clear = clear(prompt);
if (this.lineCount && !this.done) {
let pos = cursor.up(this.lineCount);
pos += cursor.left+cursor.to(length);
pos += cursor.move(-this.rendered.length+this.cursor*this.scale);
this.out.write(pos);
}
}

@@ -167,0 +203,0 @@ }

@@ -11,2 +11,4 @@ const color = require('kleur');

* @param {Boolean} [opts.initial] Default value (true/false)
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -13,0 +15,0 @@ class ConfirmPrompt extends Prompt {

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

* @param {Number} [opts.max] Max choices
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -18,0 +20,0 @@ class MultiselectPrompt extends Prompt {

const color = require('kleur');
const Prompt = require('./prompt');
const { cursor, erase } = require('sisteransi');
const { style, clear } = require('../util');
const { style, clear, figures, strip } = require('../util');

@@ -25,2 +25,5 @@ const isNumber = /[0-9]/;

* @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
* @param {Function} [opts.validate] Validate function
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -38,4 +41,7 @@ class NumberPrompt extends Prompt {

this.max = isDef(opts.max) ? opts.max : Infinity;
this.value = ''
this.typed = '';
this.errorMsg = `Please Enter A Valid Value`;
this.validator = opts.validate || (() => true);
this.color = `cyan`;
this.value = ``;
this.typed = ``;
this.lastHit = 0;

@@ -49,3 +55,3 @@ this.render();

this.rendered = color.gray(this.transform.render(`${this.initial}`));
this._value = '';
this._value = ``;
} else {

@@ -68,8 +74,8 @@ this.placeholder = false;

valid(c) {
return c === '-' || c === '.' && this.float || isNumber.test(c)
return c === `-` || c === `.` && this.float || isNumber.test(c)
}
reset() {
this.typed = '';
this.value = '';
this.typed = ``;
this.value = ``;
this.fire();

@@ -81,18 +87,36 @@ this.render();

let x = this.value;
this.value = x !== '' ? x : this.initial;
this.value = x !== `` ? x : this.initial;
this.done = this.aborted = true;
this.error = false;
this.fire();
this.render();
this.out.write('\n');
this.out.write(`\n`);
this.close();
}
submit() {
async validate() {
let valid = await this.validator(this.value);
if (typeof valid === `string`) {
this.errorMsg = valid;
valid = false;
}
this.error = !valid;
}
async submit() {
await this.validate();
if (this.error) {
this.color = `red`;
this.fire();
this.render();
return;
}
let x = this.value;
this.value = x !== '' ? x : this.initial
this.value = x !== `` ? x : this.initial
this.done = true;
this.aborted = false;
this.error = false;
this.fire();
this.render();
this.out.write('\n');
this.out.write(`\n`);
this.close();

@@ -102,5 +126,6 @@ }

up() {
this.typed = '';
this.typed = ``;
if (this.value >= this.max) return this.bell();
this.value += this.inc;
this.color = `cyan`;
this.fire();

@@ -111,5 +136,6 @@ this.render();

down() {
this.typed = '';
this.typed = ``;
if (this.value <= this.min) return this.bell();
this.value -= this.inc;
this.color = `cyan`;
this.fire();

@@ -122,3 +148,4 @@ this.render();

if (val.length === 0) return this.bell();
this.value = this.parse((val = val.slice(0, -1))) || '';
this.value = this.parse((val = val.slice(0, -1))) || ``;
this.color = `cyan`;
this.fire();

@@ -138,7 +165,8 @@ this.render();

const now = Date.now();
if (now - this.lastHit > 1000) this.typed = ''; // 1s elapsed
if (now - this.lastHit > 1000) this.typed = ``; // 1s elapsed
this.typed += c;
this.lastHit = now;
this.color = `cyan`;
if (c === '.') return this.fire();
if (c === `.`) return this.fire();

@@ -153,13 +181,27 @@ this.value = Math.min(this.parse(this.typed), this.max);

render() {
let clear = erase.line + (this.lines ? erase.down(this.lines) : ``) + cursor.to(0);
this.lines = 0;
let error = ``;
if (this.error) {
let lines = this.errorMsg.split(`\n`);
error += lines.reduce((a, l, i) => a += `\n${i ? ` ` : figures.pointerSmall} ${color.red.italic(l)}`, ``);
this.lines = lines.length;
}
let underline = !this.done || (!this.done && !this.placeholder);
this.out.write(
erase.line +
cursor.to(0) +
[
style.symbol(this.done, this.aborted),
color.bold(this.msg),
style.delimiter(this.done),
underline ? color.cyan.underline(this.rendered) : this.rendered
].join(' ')
);
let prompt = [
style.symbol(this.done, this.aborted),
color.bold(this.msg),
style.delimiter(this.done),
underline ? color[this.color].underline(this.rendered) : this.rendered
].join(` `);
let position = ``;
if (this.lines) {
position += cursor.up(this.lines);
position += cursor.left+cursor.to(strip(prompt).length);
}
this.out.write(clear+prompt+error+position);
}

@@ -166,0 +208,0 @@ }

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

* Base prompt skeleton
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -12,0 +14,0 @@ class Prompt extends EventEmitter {

@@ -15,2 +15,4 @@ 'use strict';

* @param {Number} [opts.initial] Index of default value
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -94,4 +96,3 @@ class SelectPrompt extends Prompt {

// Print prompt
this.out.write(
[
this.out.write([
style.symbol(this.done, this.aborted),

@@ -101,4 +102,3 @@ color.bold(this.msg),

this.done ? this.values[this.cursor].title : color.gray(this.hint)
].join(' ')
);
].join(' '));

@@ -105,0 +105,0 @@ // Print choices

const color = require('kleur');
const Prompt = require('./prompt');
const { cursor } = require('sisteransi');
const { style, clear } = require('../util');
const { style, clear, strip, figures } = require('../util');

@@ -12,2 +12,5 @@ /**

* @param {String} [opts.initial] Default value
* @param {Function} [opts.validate] Validate function
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -20,6 +23,8 @@ class TextPrompt extends Prompt {

this.msg = opts.message;
this.initial = opts.initial || '';
this.value = '';
this.initial = opts.initial || ``;
this.validator = opts.validate || (() => true);
this.value = ``;
this.errorMsg = `Please Enter A Valid Value`;
this.cursor = Number(!!this.initial);
this.clear = clear('');
this.clear = clear(``);
this.render();

@@ -45,3 +50,4 @@ }

reset() {
this.value = '';
this.value = ``;
this.cursor = Number(!!this.initial);
this.fire();

@@ -54,2 +60,4 @@ this.render();

this.done = this.aborted = true;
this.error = false;
this.red = false;
this.fire();

@@ -61,4 +69,20 @@ this.render();

submit() {
async validate() {
let valid = await this.validator(this.value);
if (typeof valid === `string`) {
this.errorMsg = valid;
valid = false;
}
this.error = !valid;
}
async submit() {
this.value = this.value || this.initial;
await this.validate();
if (this.error) {
this.red = true;
this.fire();
this.render();
return;
}
this.done = true;

@@ -90,2 +114,3 @@ this.aborted = false;

this.value = `${s1}${c}${s2}`;
this.red = false;
if (this.placeholder) this.cursor = 0;

@@ -100,2 +125,3 @@ this.render();

this.value = `${s1}${s2}`;
this.red = false;
this.moveCursor(-1);

@@ -128,16 +154,31 @@ this.render();

render() {
const prompt = [
let erase = (this.lines ? cursor.down(this.lines) : ``)+this.clear;
this.lines = 0;
let prompt = [
style.symbol(this.done, this.aborted),
color.bold(this.msg),
style.delimiter(this.done),
this.rendered
].join(' ');
this.red ? color.red(this.rendered) : this.rendered
].join(` `);
this.out.write(this.clear + prompt);
this.out.write(cursor.move(this.placeholder ?
let error = ``;
if (this.error) {
let lines = this.errorMsg.split(`\n`);
error += lines.reduce((a, l, i) => a += `\n${i ? ' ' : figures.pointerSmall} ${color.red.italic(l)}`, ``);
this.lines = lines.length;
}
let position = ``;
if (this.lines) {
position += cursor.up(this.lines);
position += cursor.left+cursor.to(strip(prompt).length);
}
position += cursor.move(this.placeholder ?
-this.initial.length*this.scale :
-this.rendered.length + this.cursor*this.scale
));
-this.rendered.length+this.cursor*this.scale
);
this.clear = clear(prompt);
this.out.write(erase+prompt+error+position);
this.clear = clear(prompt+error);
}

@@ -144,0 +185,0 @@ }

@@ -13,2 +13,4 @@ const color = require('kleur');

* @param {String} [opts.inactive='off'] Inactive label
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
*/

@@ -15,0 +17,0 @@ class TogglePrompt extends Prompt {

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

const ignore = ['suggest', 'format', 'onState'];
const passOn = ['suggest', 'format', 'onState', 'validate'];
const noop = () => {};

@@ -29,5 +29,5 @@

// if property is a function, invoke it unless it's ignored
// if property is a function, invoke it unless it's a special function
for (let key in question) {
if (ignore.includes(key)) continue;
if (passOn.includes(key)) continue;
let value = question[key];

@@ -34,0 +34,0 @@ question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;

@@ -23,2 +23,5 @@ 'use strict';

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -33,4 +36,6 @@ */

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input
*
*/

@@ -47,2 +52,5 @@ $.password = args => {

* @param {function} [args.onState] On state change callback
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -66,2 +74,5 @@ */

* @param {Number} [opts.increment=1] Number to increment by when using arrow-keys
* @param {function} [args.validate] Function to validate user input
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -76,2 +87,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -88,2 +101,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input, in form of an `Array`

@@ -105,2 +120,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -117,2 +134,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -130,2 +149,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -156,2 +177,4 @@ */

* @param {function} [args.onState] On state change callback
* @param {Stream} [opts.stdin] The Readable stream to listen to
* @param {Stream} [opts.stdout] The Writable stream to write readline data to
* @returns {Promise} Promise with user input

@@ -158,0 +181,0 @@ */

{
"name": "prompts",
"version": "0.1.14",
"version": "1.0.0",
"description": "Lightweight, beautiful and user-friendly prompts",
"homepage": "https://github.com/terkelg/prompts",
"license": "MIT",
"repository": "terkelg/prompts",

@@ -35,3 +35,3 @@ "main": "index.js",

"kleur": "^2.0.1",
"sisteransi": "^0.1.1"
"sisteransi": "^1.0.0"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -17,5 +17,7 @@ <p align="center">

</a>
<!---
<a href="https://packagephobia.now.sh/result?p=prompts">
<img src="https://packagephobia.now.sh/badge?p=prompts" alt="install size" />
</a>
--->
</p>

@@ -53,3 +55,3 @@

<img src="https://github.com/terkelg/prompts/raw/master/media/number.gif" alt="example prompt" width="499" height="103" />
<img src="https://github.com/terkelg/prompts/raw/master/media/example.gif" alt="example prompt" width="499" height="103" />

@@ -62,6 +64,7 @@ ```js

name: 'value',
message: 'How old are you?'
message: 'How old are you?',
validate: value => value < 18 ? `Nightclub is 18+ only` : true
});
console.log(response); // => { value: 23 }
console.log(response); // => { value: 24 }
```

@@ -253,7 +256,7 @@

{
type: String || Function,
name: String || Function,
message: String || Function,
initial: String || Function || Async Function
format: Function || Async Function,
type: String | Function,
name: String | Function,
message: String | Function,
initial: String | Function | Async Function
format: Function | Async Function,
onState: Function

@@ -352,2 +355,4 @@ }

Hit <kbd>tab</kbd> to autocomplete to `initial` value when provided.
#### Example

@@ -360,5 +365,3 @@ <img src="https://github.com/terkelg/prompts/raw/master/media/text.gif" alt="text prompt" width="499" height="103" />

name: 'value',
message: `What's your twitter handle?`,
style: 'default',
initial: ''
message: `What's your twitter handle?`
}

@@ -368,9 +371,10 @@ ```

#### Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| initial | <code>string</code> | <code>''</code> | Default string value |
| style | <code>string</code> | <code>'default'</code> | Render style (`default`, `password`, `invisible`) |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| initial | `string` | Default string value |
| style | `string` | Render style (`default`, `password`, `invisible`, `emoji`). Defaults to `default` |
| format | `function` | Receive user input. The returned value will be added to the response object |
| validate | `function` | Receive user input. Should return `true` if the value is valid, and an error message `String` otherwise. If `false` is returned, a default error message is shown |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -390,4 +394,3 @@

name: 'value',
message: 'Tell me a secret',
initial '',
message: 'Tell me a secret'
}

@@ -399,6 +402,7 @@ ```

| --- | --- | --- |
| message | <code>string</code> | Prompt message to display |
| initial | <code>string</code> | Default string value |
| format | <code>function</code> | Receive user input. The returned value will be added to the response object |
| onState | <code>function</code> | On state change callback |
| message | `string` | Prompt message to display |
| initial | `string` | Default string value |
| format | `function` | Receive user input. The returned value will be added to the response object |
| validate | `function` | Receive user input. Should return `true` if the value is valid, and an error message `String` otherwise. If `false` is returned, a default error message is shown |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -419,4 +423,3 @@

name: 'value',
message: 'Enter password',
initial: ''
message: 'Enter password'
}

@@ -428,6 +431,7 @@ ```

| --- | --- | --- |
| message | <code>string</code> | Prompt message to display |
| initial | <code>string</code> | Default string value |
| format | <code>function</code> | Receive user input. The returned value will be added to the response object |
| onState | <code>function</code> | On state change callback |
| message | `string` | Prompt message to display |
| initial | `string` | Default string value |
| format | `function` | Receive user input. The returned value will be added to the response object |
| validate | `function` | Receive user input. Should return `true` if the value is valid, and an error message `String` otherwise. If `false` is returned, a default error message is shown |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -438,3 +442,3 @@

You can type in numbers and use <kbd>up</kbd>/<kbd>down</kbd> to increase/decrease the value. Only numbers are allowed as input.
You can type in numbers and use <kbd>up</kbd>/<kbd>down</kbd> to increase/decrease the value. Only numbers are allowed as input. Hit <kbd>tab</kbd> to autocomplete to `initial` value when provided.

@@ -457,11 +461,15 @@ #### Example

#### Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| initial | <code>number</code> | `null` | Default number value |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| max | <code>number</code> | `Infinity` | Max value |
| min | <code>number</code> | `-infinity` | Min value |
| style | <code>string</code> | <code>'default'</code> | Render style (`default`, `password`, `invisible`) |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| initial | `number` | Default number value |
| format | `function` | Receive user input. The returned value will be added to the response object |
| validate | `function` | Receive user input. Should return `true` if the value is valid, and an error message `String` otherwise. If `false` is returned, a default error message is shown |
| max | `number` | Max value. Defaults to `Infinity` |
| min | `number` | Min value. Defaults to `-infinity` |
| float | `boolean` | Allow floating point inputs. Defaults to `false` |
| round | `number` | Round `float` values to x decimals. Defaults to `2` |
| increment | `number` | Increment step when using <kbd>arrow</kbd> keys. Defaults to `1` |
| style | `string` | Render style (`default`, `password`, `invisible`, `emoji`). Defaults to `default` |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -487,8 +495,8 @@ ### confirm(message, [initial])

#### Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| initial | <code>boolean</code> | <code>false</code> | Default value |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| initial | `boolean` | Default value. Default is `false` |
| format | `function` | Receive user input. The returned value will be added to the response object |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -514,9 +522,9 @@ ### list(message, [initial])

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| initial | <code>boolean</code> | <code>false</code> | Default value |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| separator | <code>string</code> | <code>','</code> | String separator. Will trim all white-spaces from start and end of string |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| initial | `boolean` | Default value |
| format | `function` | Receive user input. The returned value will be added to the response object |
| separator | `string` | String separator. Will trim all white-spaces from start and end of string. Defaults to `','` |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -544,10 +552,10 @@

#### Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| initial | <code>boolean</code> | <code>false</code> | Default value |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| active | <code>string</code> | <code>'on'</code> | Text for `active` state |
| inactive | <code>string</code> | <code>'off'</code> | Text for `inactive` state |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| initial | `boolean` | Default value. Defaults to `false` |
| format | `function` | Receive user input. The returned value will be added to the response object |
| active | `string` | Text for `active` state. Defaults to `'on'` |
| inactive | `string` | Text for `inactive` state. Defaults to `'off'` |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -579,7 +587,7 @@ ### select(message, choices, [initial])

| --- | --- | --- |
| message | <code>string</code> | Prompt message to display |
| initial | <code>number</code> | Index of default value |
| format | <code>function</code> | Receive user input. The returned value will be added to the response object |
| choices | <code>Array</code> | Array of choices objects `[{ title, value }, ...]` |
| onState | <code>function</code> | On state change callback |
| message | `string` | Prompt message to display |
| initial | `number` | Index of default value |
| format | `function` | Receive user input. The returned value will be added to the response object |
| choices | `Array` | Array of choices objects `[{ title, value }, ...]` |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -615,8 +623,8 @@

| --- | --- | --- |
| message | <code>string</code> | Prompt message to display |
| format | <code>function</code> | Receive user input. The returned value will be added to the response object |
| choices | <code>Array</code> | Array of choices objects `[{ title, value, [selected] }, ...]` |
| max | <code>number</code> | Max select |
| hint | <code>string</code> | Hint to display user |
| onState | <code>function</code> | On state change callback |
| message | `string` | Prompt message to display |
| format | `function` | Receive user input. The returned value will be added to the response object |
| choices | `Array` | Array of choices objects `[{ title, value, [selected] }, ...]` |
| max | `number` | Max select |
| hint | `string` | Hint to display user |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -655,11 +663,13 @@ This is one of the few prompts that don't take a initial value.

#### Options
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| message | <code>string</code> | | Prompt message to display |
| format | <code>function</code> | | Receive user input. The returned value will be added to the response object |
| choices | <code>Array</code> | | Array of auto-complete choices objects `[{ title, value }, ...]` |
| suggest | <code>function</code> | By `title` string | Filter function. Defaults to sort by `title` property. `suggest` should always return a promise |
| limit | <code>number</code> | <code>10</code> | Max number of results to show |
| style | <code>string</code> | `'default'` | Render style (`default`, `password`, `invisible`) |
| onState | <code>function</code> | | On state change callback |
| Param | Type | Description |
| --- | --- | --- |
| message | `string` | Prompt message to display |
| format | `function` | Receive user input. The returned value will be added to the response object |
| choices | `Array` | Array of auto-complete choices objects `[{ title, value }, ...]` |
| suggest | `function` | Filter function. Defaults to sort by `title` property. `suggest` should always return a promise. Filters using `title` by default |
| limit | `number` | Max number of results to show. Defaults to `10` |
| style | `string` | Render style (`default`, `password`, `invisible`, `emoji`). Defaults to `'default'` |
| initial | Default initial value |
| fallback | Fallback message when no match is found. Defaults to `initial` value if provided |
| onState | `function` | On state change callback. Function signature is an `object` with two propetires: `value` and `aborted` |

@@ -666,0 +676,0 @@ Example on what a `suggest` function might look like:

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