Socket
Socket
Sign inDemoInstall

prompt-choices

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompt-choices - npm Package Compare versions

Comparing version 4.0.6 to 4.1.0

122

index.js
'use strict';
var swap = require('arr-swap');
var Paginator = require('terminal-paginator');
var debug = require('debug')('prompt-choices');
var define = require('define-property');
var visit = require('collection-visit');
var Choice = require('./lib/choice');
var utils = require('./lib/utils');
const swap = require('arr-swap');
const Paginator = require('terminal-paginator');
const define = require('define-property');
const visit = require('collection-visit');
const Choice = require('./lib/choice');
const utils = require('./lib/utils');

@@ -15,4 +14,4 @@ /**

* ```js
* var choices = new Choices(['foo', 'bar', 'baz']);
* var choices = new Choices([{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]);
* const choices = new Choices(['foo', 'bar', 'baz']);
* const choices = new Choices([{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]);
* ```

@@ -24,3 +23,2 @@ * @param {Array} `choices` One or more `choice` strings or objects.

function Choices(choices, options) {
debug('initializing from <%s>', __filename);
if (utils.isObject(choices) && choices.isChoices) {

@@ -57,4 +55,4 @@ return choices;

Choices.prototype.render = function(position, options) {
var opts = utils.extend({limit: 7}, this.options, options);
var buf = '';
const opts = Object.assign({limit: 7}, this.options, options);
let buf = '';

@@ -66,12 +64,12 @@ if (opts.radio === true) {

this.position = position || 0;
for (var i = 0; i < this.choices.length; i++) {
var choice = this.choices[i];
for (let i = 0; i < this.choices.length; i++) {
let choice = this.choices[i];
if (opts && typeof opts.renderChoice === 'function') {
buf += opts.renderChoice.call(this, this.position, choice, opts);
} else {
buf += choice.render(this.position, opts);
buf += this.renderChoice(choice, this.position, opts);
}
}
var str = '\n' + buf.replace(/\s+$/, '');
const str = '\n' + buf.replace(/\s+$/, '');
return this.paginator.paginate(str, this.position, opts);

@@ -112,3 +110,3 @@ };

Choices.prototype.choice = function(val) {
var choice = new Choice(val, this.options);
const choice = new Choice(val, this.options);
define(choice, 'parent', this);

@@ -193,4 +191,4 @@ return choice;

for (var i = 0; i < choices.length; i++) {
this.addChoice(choices[i]);
for (const choice of choices) {
this.addChoice(choice);
}

@@ -219,12 +217,12 @@ };

var line = this.separator(this.options);
var keys = Object.keys(choices);
var head = [];
var tail = this.options.radio ? [line] : [];
var items = [];
let line = this.separator(this.options);
let keys = Object.keys(choices);
let head = [];
let tail = this.options.radio ? [line] : [];
let items = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = choices[key];
var arr = (utils.isObject(val) && val.choices) ? val.choices : val;
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let val = choices[key];
let arr = (utils.isObject(val) && val.choices) ? val.choices : val;

@@ -235,3 +233,3 @@ if (!Array.isArray(arr)) {

var select = this.choice({
let select = this.choice({
name: key,

@@ -247,4 +245,4 @@ type: 'group',

for (var j = 0; j < arr.length; j++) {
var choice = this.choice(arr[j]);
for (let j = 0; j < arr.length; j++) {
let choice = this.choice(arr[j]);
choice.type = 'option';

@@ -260,7 +258,7 @@ choice.group = select;

var none = {name: 'none', type: 'radio', choices: items};
var all = {name: 'all', type: 'radio', choices: items};
if (keys.length === 1 && arr.length <= 2) {
let none = {name: 'none', type: 'radio', choices: items};
let all = {name: 'all', type: 'radio', choices: items};
if (keys.length === 1 && items.length <= 2) {
return tail.filter(function(choice) {
var isOption = choice.type === 'option';
let isOption = choice.type === 'option';
delete choice.type;

@@ -331,3 +329,3 @@ return isOption;

var choice = this.items[idx];
const choice = this.items[idx];
if (choice) {

@@ -343,3 +341,3 @@ choice.index = idx;

* ```js
* var choices = new Choices(['foo', 'bar', 'baz']);
* const choices = new Choices(['foo', 'bar', 'baz']);
* console.log(choices.getIndex('foo')); //=> 0

@@ -369,5 +367,5 @@ * console.log(choices.getIndex('baz')); //=> 2

* ```js
* var choice = choices.get(1);
* const choice = choices.get(1);
* //=> {name: 'foo'}
* var choice = choices.get(1, 'name');
* const choice = choices.get(1, 'name');
* //=> 'foo'

@@ -387,3 +385,3 @@ * ```

}
var choice = this.getChoice(key);
const choice = this.getChoice(key);
if (choice && typeof prop === 'string') {

@@ -441,3 +439,3 @@ return choice[prop];

}
var choice = this.get(val);
const choice = this.get(val);
if (choice != null) {

@@ -467,3 +465,3 @@ choice.checked = true;

}
var choice = this.get(val);
const choice = this.get(val);
if (choice) {

@@ -479,3 +477,3 @@ choice.checked = false;

* ```js
* var choices = new Choices(['foo', 'bar', 'baz']);
* const choices = new Choices(['foo', 'bar', 'baz']);
* console.log(choices.isChecked('foo'));

@@ -494,4 +492,4 @@ * //=> false

if (Array.isArray(name)) {
for (var i = 0; i < name.length; i++) {
if (!this.isChecked(name[i])) {
for (const ele of name) {
if (!this.isChecked(ele)) {
return false;

@@ -503,3 +501,3 @@ }

var choice = this.get(name);
const choice = this.get(name);
if (choice) {

@@ -532,3 +530,3 @@ return choice.checked === true;

var choice = this.get(val);
const choice = this.get(val);
if (!choice) {

@@ -560,3 +558,3 @@ return this;

Choices.prototype.radio = function() {
var choice = this.get(this.position);
const choice = this.get(this.position);
if (!choice) return;

@@ -633,3 +631,3 @@

Choices.prototype.swap = function(a, b) {
var choices = swap(this.choices.slice(), a, b);
const choices = swap(this.choices.slice(), a, b);
this.clear();

@@ -668,3 +666,3 @@ this.addChoices(choices);

return this.filter(function(choice) {
for (var key in val) {
for (const key in val) {
if (!choice.hasOwnProperty(key)) {

@@ -679,5 +677,5 @@ return false;

if (Array.isArray(val)) {
var acc = [];
for (var i = 0; i < val.length; i++) {
acc = acc.concat(this.where.call(this, val[i]));
let acc = [];
for (const ele of val) {
acc = acc.concat(this.where.call(this, ele));
}

@@ -768,6 +766,3 @@ return acc;

if (this._default == null) {
var len = this.items.length;
var idx = -1;
while (++idx < len) {
var choice = this.items[idx];
for (const choice of this.items) {
if (choice.default === true) {

@@ -779,3 +774,2 @@ define(this, '_default', choice.index);

}
if (this._default != null) {

@@ -816,3 +810,3 @@ this.check(this.getIndex(this._default));

get: function() {
var items = this.filter(this.isItem);
const items = this.filter(this.isItem);
return items.length === this.checked.length;

@@ -863,4 +857,4 @@ }

* ```js
* var Choices = require('prompt-choices');
* var choices = new Choices(['foo']);
* const Choices = require('prompt-choices');
* const choices = new Choices(['foo']);
* console.log(Choices.isChoices(choices)); //=> true

@@ -882,5 +876,5 @@ * console.log(Choices.isChoices({})); //=> false

* ```js
* var Choices = require('prompt-choices');
* var choices = new Choices(['foo']);
* var foo = choices.getChoice('foo');
* const Choices = require('prompt-choices');
* const choices = new Choices(['foo']);
* const foo = choices.getChoice('foo');
* console.log(Choices.isChoice(foo)); //=> true

@@ -887,0 +881,0 @@ * console.log(Choices.isChoice({})); //=> false

'use strict';
var log = require('log-utils');
var koalas = require('koalas');
var extend = require('extend-shallow');
var define = require('define-property');
var pointer = require('pointer-symbol');
var radio = require('radio-symbol');
var strip = require('strip-color');
var utils = require('./utils');
const log = require('log-utils');
const koalas = require('koalas');
const define = require('define-property');
const pointer = require('pointer-symbol');
const radio = require('radio-symbol');
const strip = require('strip-color');
const utils = require('./utils');

@@ -53,3 +52,3 @@ /**

define(this, 'options', options || {});
extend(this, choice);
Object.assign(this, choice);

@@ -56,0 +55,0 @@ this.name = choice.name || choice.value;

'use strict';
var isNumber = require('is-number');
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
const isNumber = require('is-number');
/**
* Lazily required module dependencies
* Lazily require module dependencies in a way that is both
* friendly to node.js and webpack/browserify.
*/
require('arr-flatten', 'flatten');
require('clone-deep', 'clone');
require('choices-separator', 'Separator');
require('define-property', 'define');
require('extend-shallow', 'extend');
require('kind-of', 'typeOf');
require('toggle-array', 'toggle');
require('set-value', 'set');
require = fn;
define(exports, 'flatten', () => require('arr-flatten'));
define(exports, 'clone', () => require('clone-deep'));
define(exports, 'Separator', () => require('choices-separator'));
define(exports, 'define', () => require('define-property'));
define(exports, 'typeOf', () => require('kind-of'));
define(exports, 'toggle', () => require('toggle-array'));
define(exports, 'set', () => require('set-value'));
function define(obj, key, value) {
Reflect.defineProperty(obj, key, { get: value });
}
/**

@@ -27,3 +27,3 @@ * Returns true if `val` is a number (also ensures that val

utils.isNumber = function(val) {
exports.isNumber = function(val) {
return isNumber(val) && String(val).trim() !== '';

@@ -37,4 +37,4 @@ };

utils.isObject = function(val) {
return utils.typeOf(val) === 'object';
exports.isObject = function(val) {
return exports.typeOf(val) === 'object';
};

@@ -46,10 +46,4 @@

utils.arrayify = function(val) {
exports.arrayify = function(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
};
/**
* Expose `utils` modules
*/
module.exports = utils;
{
"name": "prompt-choices",
"description": "Create an array of multiple choice objects for use in prompts.",
"version": "4.0.6",
"version": "4.1.0",
"homepage": "https://github.com/enquirer/prompt-choices",

@@ -27,15 +27,12 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"choices-separator": "^2.0.0",
"clone-deep": "^1.0.0",
"clone-deep": "^4.0.0",
"collection-visit": "^1.0.0",
"debug": "^3.0.1",
"define-property": "^1.0.0",
"extend-shallow": "^2.0.1",
"is-number": "^3.0.0",
"kind-of": "^5.0.2",
"define-property": "^2.0.2",
"is-number": "^6.0.0",
"kind-of": "^6.0.2",
"koalas": "^1.0.2",
"lazy-cache": "^2.0.2",
"log-utils": "^0.2.1",
"pointer-symbol": "^1.0.0",
"radio-symbol": "^2.0.0",
"set-value": "^2.0.0",
"set-value": "^3.0.0",
"strip-color": "^0.1.0",

@@ -46,10 +43,5 @@ "terminal-paginator": "^2.0.2",

"devDependencies": {
"gulp": "^3.9.1",
"gulp-eslint": "^4.0.0",
"gulp-format-md": "^1.0.0",
"gulp-istanbul": "^1.1.2",
"gulp-mocha": "^3.0.1",
"gulp-unused": "^0.2.1",
"is-windows": "^1.0.1",
"mocha": "^3.5.0",
"is-windows": "^1.0.2",
"mocha": "^5.2.0",
"prompt-actions": "^3.0.2"

@@ -56,0 +48,0 @@ },

@@ -5,3 +5,3 @@ # prompt-choices [![NPM version](https://img.shields.io/npm/v/prompt-choices.svg?style=flat)](https://www.npmjs.com/package/prompt-choices) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-choices.svg?style=flat)](https://npmjs.org/package/prompt-choices) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-choices.svg?style=flat)](https://npmjs.org/package/prompt-choices) [![Linux Build Status](https://img.shields.io/travis/enquirer/prompt-choices.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/prompt-choices)

Follow this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), for updates on this project and others.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

@@ -25,3 +25,3 @@ ## Install

### [Choices](index.js#L22)
### [Choices](index.js#L21)

@@ -37,7 +37,7 @@ Create a new `Choices` collection.

```js
var choices = new Choices(['foo', 'bar', 'baz']);
var choices = new Choices([{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]);
const choices = new Choices(['foo', 'bar', 'baz']);
const choices = new Choices([{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]);
```
### [.render](index.js#L54)
### [.render](index.js#L52)

@@ -52,4 +52,24 @@ Render choices.

### [.choice](index.js#L82)
### [.renderChoice](index.js#L90)
Render a specific choice. This can be overridden in prompts.
**Params**
* `choice` **{Object}**
* `position` **{Number}**
* `options` **{Object}**
* `returns` **{String}**: Returns the line to render.
**Example**
```js
choices.render = function(choice, position, options) {
// do custom logic
return '';
};
```
### [.choice](index.js#L105)
Create a new `Choice` object.

@@ -68,3 +88,3 @@

### [.toChoice](index.js#L100)
### [.toChoice](index.js#L123)

@@ -85,3 +105,3 @@ Returns a normalized `choice` object.

### [.addChoice](index.js#L120)
### [.addChoice](index.js#L143)

@@ -100,3 +120,3 @@ Add a normalized `choice` object to the `choices` array.

### [.addChoices](index.js#L150)
### [.addChoices](index.js#L173)

@@ -115,3 +135,3 @@ Add an array of normalized `choice` objects to the `choices` array. This method is called in the constructor, but it can also be used to add choices after instantiation.

### [.toGroups](index.js#L183)
### [.toGroups](index.js#L206)

@@ -134,3 +154,3 @@ Create choice "groups" from the given choices object. ![choice groups](docs/prompt-groups.gif).

### [.separator](index.js#L259)
### [.separator](index.js#L282)

@@ -150,3 +170,3 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details.

### [.hasChoice](index.js#L275)
### [.hasChoice](index.js#L298)

@@ -167,3 +187,3 @@ Returns true if a choice exists.

### [.getChoice](index.js#L291)
### [.getChoice](index.js#L314)

@@ -184,3 +204,3 @@ Get a non-separator choice from the collection.

### [.getIndex](index.js#L318)
### [.getIndex](index.js#L341)

@@ -197,3 +217,3 @@ Get the index of a non-separator choice from the collection.

```js
var choices = new Choices(['foo', 'bar', 'baz']);
const choices = new Choices(['foo', 'bar', 'baz']);
console.log(choices.getIndex('foo')); //=> 0

@@ -205,3 +225,3 @@ console.log(choices.getIndex('baz')); //=> 2

### [.get](index.js#L342)
### [.get](index.js#L365)

@@ -218,9 +238,9 @@ Get the choice at the specified index.

```js
var choice = choices.get(1);
const choice = choices.get(1);
//=> {name: 'foo'}
var choice = choices.get(1, 'name');
const choice = choices.get(1, 'name');
//=> 'foo'
```
### [.clear](index.js#L366)
### [.clear](index.js#L389)

@@ -235,3 +255,3 @@ Clear all choices from the instance. This is useful when you need to update the indices of choices without re-instantiating.

### [.key](index.js#L380)
### [.key](index.js#L403)

@@ -245,3 +265,3 @@ Return the `.key` property from the choice at the given index.

### [.check](index.js#L394)
### [.check](index.js#L417)

@@ -260,3 +280,3 @@ Check the choice at the given `idx`.

### [.uncheck](index.js#L419)
### [.uncheck](index.js#L442)

@@ -275,3 +295,3 @@ Disable the choice at the given `idx`.

### [.isChecked](index.js#L450)
### [.isChecked](index.js#L473)

@@ -288,3 +308,3 @@ Returns true if a choice is checked.

```js
var choices = new Choices(['foo', 'bar', 'baz']);
const choices = new Choices(['foo', 'bar', 'baz']);
console.log(choices.isChecked('foo'));

@@ -297,3 +317,3 @@ //=> false

### [.toggle](index.js#L478)
### [.toggle](index.js#L501)

@@ -314,3 +334,3 @@ Toggle the choice at the given `idx`.

### [.swap](index.js#L586)
### [.swap](index.js#L609)

@@ -325,3 +345,3 @@ Swap two choices in the choices array.

### [.where](index.js#L602)
### [.where](index.js#L625)

@@ -336,3 +356,3 @@ Return choice values for choices that return truthy based

### [.isItem](index.js#L650)
### [.isItem](index.js#L673)

@@ -347,3 +367,3 @@ Returns true if the given `choice` is a valid choice item, and

### [.isValidIndex](index.js#L665)
### [.isValidIndex](index.js#L688)

@@ -357,3 +377,3 @@ Returns true if the given `index` is a valid choice index.

### [.pluck](index.js#L676)
### [.pluck](index.js#L699)

@@ -367,15 +387,15 @@ Pluck an object with the specified key from the choices collection.

### [.default](index.js#L712)
### [.default](index.js#L735)
Getter for getting the default choice.
### [.checked](index.js#L743)
### [.checked](index.js#L762)
Getter for getting the checked choices from the collection.
### [.length](index.js#L785)
### [.length](index.js#L804)
Getter for getting the length of the collection.
### [.Separator](index.js#L805)
### [.Separator](index.js#L824)

@@ -395,3 +415,3 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details.

### [.isChoices](index.js#L821)
### [.isChoices](index.js#L840)

@@ -408,4 +428,4 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details.

```js
var Choices = require('prompt-choices');
var choices = new Choices(['foo']);
const Choices = require('prompt-choices');
const choices = new Choices(['foo']);
console.log(Choices.isChoices(choices)); //=> true

@@ -415,3 +435,3 @@ console.log(Choices.isChoices({})); //=> false

### [.isChoice](index.js#L840)
### [.isChoice](index.js#L859)

@@ -428,5 +448,5 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details.

```js
var Choices = require('prompt-choices');
var choices = new Choices(['foo']);
var foo = choices.getChoice('foo');
const Choices = require('prompt-choices');
const choices = new Choices(['foo']);
const foo = choices.getChoice('foo');
console.log(Choices.isChoice(foo)); //=> true

@@ -478,18 +498,23 @@ console.log(Choices.isChoice({})); //=> false

### Related projects
<details>
<summary><strong>Contributing</strong></summary>
You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. | [homepage](http://enquirer.io "Intuitive, plugin-based prompt system for node.js.")
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompts. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompts.")
* [prompt-checkbox](https://www.npmjs.com/package/prompt-checkbox): Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer]. | [homepage](https://github.com/enquirer/prompt-checkbox "Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer].")
* [prompt-question](https://www.npmjs.com/package/prompt-question): Question object, used by Enquirer and prompt plugins. | [homepage](https://github.com/enquirer/prompt-question "Question object, used by Enquirer and prompt plugins.")
* [prompt-radio](https://www.npmjs.com/package/prompt-radio): Radio prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer]. | [homepage](https://github.com/enquirer/prompt-radio "Radio prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer].")
</details>
### Contributing
<details>
<summary><strong>Running Tests</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
### Building docs
```sh
$ npm install && npm test
```
</details>
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

@@ -503,10 +528,14 @@

### Running tests
</details>
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
### Related projects
```sh
$ npm install && npm test
```
You might also be interested in these projects:
* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. | [homepage](http://enquirer.io "Intuitive, plugin-based prompt system for node.js.")
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompts. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompts.")
* [prompt-checkbox](https://www.npmjs.com/package/prompt-checkbox): Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer]. | [homepage](https://github.com/enquirer/prompt-checkbox "Multiple-choice/checkbox prompt. Can be used standalone or with a prompt system like [Enquirer].")
* [prompt-question](https://www.npmjs.com/package/prompt-question): Question object, used by Enquirer and prompt plugins. | [homepage](https://github.com/enquirer/prompt-question "Question object, used by Enquirer and prompt plugins.")
* [prompt-radio](https://www.npmjs.com/package/prompt-radio): Radio prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer]. | [homepage](https://github.com/enquirer/prompt-radio "Radio prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer].")
### Author

@@ -516,8 +545,9 @@

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

@@ -527,2 +557,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 28, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 28, 2018._

Sorry, the diff of this file is not supported yet

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