prompt-choices
Advanced tools
Comparing version 0.4.1 to 0.5.0
28
index.js
@@ -48,3 +48,2 @@ 'use strict'; | ||
var len = this.choices.length; | ||
var num = opts.limit || 7; | ||
var idx = -1; | ||
@@ -59,6 +58,3 @@ var buf = ''; | ||
var str = '\n' + buf.replace(/\n$/, ''); | ||
if (len > num && opts.paginate) { | ||
return this.paginator.paginate(str, position, num); | ||
} | ||
return str; | ||
return this.paginator.paginate(str, position, opts.limit); | ||
}; | ||
@@ -140,3 +136,20 @@ | ||
* ```js | ||
* choices.hasChoice(1); | ||
* choices.hasChoice('foo'); | ||
* ``` | ||
* @param {Number} `idx` The selected choice index | ||
* @return {Object|undefined} Return the matched choice object or undefined | ||
* @api public | ||
*/ | ||
Choices.prototype.hasChoice = function(val) { | ||
return !!this.getChoice(val); | ||
}; | ||
/** | ||
* Get a non-separator choice from the collection. | ||
* | ||
* ```js | ||
* choices.getChoice(1); | ||
* choices.getChoice('foo'); | ||
* ``` | ||
@@ -257,4 +270,2 @@ * @param {Number} `idx` The selected choice index | ||
Choices.prototype.where = function(val) { | ||
var res = []; | ||
if (typeof val === 'function') { | ||
@@ -360,5 +371,6 @@ return this.filter(val); | ||
get: function() { | ||
var opts = this.options; | ||
return this.items.reduce(function(acc, choice) { | ||
if (choice.checked === true) { | ||
acc.push(choice.value); | ||
acc.push((opts.radio || opts.choiceObject) ? choice : choice.value); | ||
} | ||
@@ -365,0 +377,0 @@ return acc; |
@@ -43,2 +43,3 @@ 'use strict'; | ||
this.checked = false; | ||
utils.define(this, 'position', 0); | ||
@@ -104,6 +105,7 @@ utils.define(this, 'index', 0); | ||
get: function() { | ||
if (typeof this.options.symbol === 'string') { | ||
return this.options.symbol; | ||
var symbol = this.options.checkbox || radio; | ||
if (this.disabled) { | ||
return symbol.disabled; | ||
} | ||
return this.disabled ? radio.disabled : (this.checked ? radio.on : radio.off); | ||
return this.checked ? symbol.on : symbol.off; | ||
} | ||
@@ -154,7 +156,2 @@ }); | ||
function disabled(choice) { | ||
var symbol = process.platform === 'win32' ? ' (×) ' : ' ⓧ '; | ||
return log.dim(symbol + choice.name + ' (' + (choice.disabled || 'Disabled') + ')'); | ||
} | ||
/** | ||
@@ -161,0 +158,0 @@ * Expose Choice |
@@ -46,3 +46,3 @@ 'use strict'; | ||
utils.isNumber = function(val) { | ||
return isNumber(val) && !/^\s+$/.test(String(val)); | ||
return isNumber(val) && String(val).trim() !== ''; | ||
}; | ||
@@ -49,0 +49,0 @@ |
{ | ||
"name": "prompt-choices", | ||
"description": "Create an array of multiple choice objects for use in prompts.", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/enquirer/prompt-choices", | ||
@@ -27,13 +27,12 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"clone-deep": "^0.2.4", | ||
"debug": "^2.2.0", | ||
"debug": "^2.6.3", | ||
"define-property": "^0.2.5", | ||
"extend-shallow": "^2.0.1", | ||
"is-number": "^3.0.0", | ||
"isobject": "^2.1.0", | ||
"kind-of": "^3.0.4", | ||
"lazy-cache": "^2.0.1", | ||
"kind-of": "^3.1.0", | ||
"lazy-cache": "^2.0.2", | ||
"log-utils": "^0.2.1", | ||
"radio-symbol": "^0.2.1", | ||
"set-value": "^0.4.0", | ||
"terminal-paginator": "^0.2.0", | ||
"set-value": "^0.4.3", | ||
"terminal-paginator": "^0.2.1", | ||
"toggle-array": "^0.1.0" | ||
@@ -44,7 +43,7 @@ }, | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-format-md": "^0.1.10", | ||
"gulp-format-md": "^0.1.12", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-unused": "^0.2.0", | ||
"mocha": "^3.0.2" | ||
"gulp-mocha": "^3.0.0", | ||
"gulp-unused": "^0.2.1", | ||
"mocha": "^3.2.0" | ||
}, | ||
@@ -92,3 +91,7 @@ "keywords": [ | ||
"related": { | ||
"list": [] | ||
"list": [ | ||
"enquirer", | ||
"prompt-base", | ||
"prompt-question" | ||
] | ||
}, | ||
@@ -95,0 +98,0 @@ "reflinks": [ |
117
README.md
@@ -1,2 +0,2 @@ | ||
# prompt-choices [![NPM version](https://img.shields.io/npm/v/prompt-choices.svg?style=flat)](https://www.npmjs.com/package/prompt-choices) [![NPM downloads](https://img.shields.io/npm/dm/prompt-choices.svg?style=flat)](https://npmjs.org/package/prompt-choices) [![Build Status](https://img.shields.io/travis/enquirer/prompt-choices.svg?style=flat)](https://travis-ci.org/enquirer/prompt-choices) | ||
# 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) | ||
@@ -37,4 +37,14 @@ > Create an array of multiple choice objects for use in prompts. | ||
### [.addChoices](index.js#L44) | ||
### [.render](index.js#L45) | ||
Render the current choices. | ||
**Params** | ||
* `position` **{Number}**: Cursor position | ||
* `options` **{Object}** | ||
* `returns` **{String}** | ||
### [.addChoices](index.js#L72) | ||
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. | ||
@@ -52,3 +62,3 @@ | ||
### [.choice](index.js#L77) | ||
### [.choice](index.js#L111) | ||
@@ -68,3 +78,3 @@ Create a new `Choice` object. | ||
### [.separator](index.js#L92) | ||
### [.separator](index.js#L126) | ||
@@ -84,3 +94,3 @@ Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details. | ||
### [.getChoice](index.js#L107) | ||
### [.hasChoice](index.js#L142) | ||
@@ -97,6 +107,23 @@ Get a non-separator choice from the collection. | ||
```js | ||
choices.hasChoice(1); | ||
choices.hasChoice('foo'); | ||
``` | ||
### [.getChoice](index.js#L158) | ||
Get a non-separator choice from the collection. | ||
**Params** | ||
* `idx` **{Number}**: The selected choice index | ||
* `returns` **{Object|undefined}**: Return the matched choice object or undefined | ||
**Example** | ||
```js | ||
choices.getChoice(1); | ||
choices.getChoice('foo'); | ||
``` | ||
### [.getIndex](index.js#L127) | ||
### [.getIndex](index.js#L176) | ||
@@ -116,3 +143,3 @@ Get the index of a non-separator choice from the collection. | ||
### [.get](index.js#L148) | ||
### [.get](index.js#L194) | ||
@@ -132,3 +159,3 @@ Get the choice or separator object at the specified index. | ||
### [.enable](index.js#L165) | ||
### [.enable](index.js#L211) | ||
@@ -147,3 +174,3 @@ Enable the choice at the given `idx`. | ||
### [.disable](index.js#L180) | ||
### [.disable](index.js#L229) | ||
@@ -162,5 +189,5 @@ Disable the choice at the given `idx`. | ||
### [.toggleChoices](index.js#L195) | ||
### [.toggle](index.js#L249) | ||
Enable the choice at the given `index`, and disable all other choices. | ||
Toggle the choice at the given `idx`. | ||
@@ -174,29 +201,35 @@ **Params** | ||
```js | ||
choices.toggleChoices(1); | ||
choices.toggle(1); | ||
// radio mode | ||
choices.toggle(1, true); | ||
``` | ||
### [.toggleChoice](index.js#L210) | ||
### [.where](index.js#L266) | ||
Toggle the choice at the given `idx`. | ||
Return choices that return truthy based on the given `val`. | ||
**Params** | ||
* `idx` **{Number}**: The index of the choice to toggle. | ||
* `val` **{Object|Function|String|RegExp}** | ||
* `returns` **{Array}**: Matching choices or empty array | ||
**Example** | ||
### [.isValidIndex](index.js#L312) | ||
```js | ||
choices.toggleChoice(1); | ||
``` | ||
Returns true if the given `index` is a valid choice index. | ||
### [.where](index.js#L224) | ||
**Params** | ||
Return choices that return truthy based on the given `val`. | ||
* `key` **{String}**: Property name to use for plucking objects. | ||
* `returns` **{Array}**: Plucked objects | ||
### [.key](index.js#L323) | ||
Return the `.key` property from the choice at the given index. | ||
**Params** | ||
* `val` **{Object|Function|String}** | ||
* `returns` **{Array}**: Matching choices or empty array | ||
* `key` **{String}**: Property name to use for plucking objects. | ||
* `returns` **{Array}**: Plucked objects | ||
### [.pluck](index.js#L259) | ||
### [.pluck](index.js#L334) | ||
@@ -210,16 +243,8 @@ Pluck an object with the specified key from the choices collection. | ||
### [.length](index.js#L302) | ||
### [.length](index.js#L362) | ||
Getter for getting the length of the collection. | ||
### [.realChoices](index.js#L317) | ||
### [.Separator](index.js#L408) | ||
Getter for getting all non-separator choices from the collection. | ||
### [.realLength](index.js#L340) | ||
Getter for getting the length of the collection excluding non-separator choices. | ||
### [.Separator](index.js#L360) | ||
Create a new `Separator` object. See [choices-separator](https://github.com/enquirer/choices-separator) for more details. | ||
@@ -244,2 +269,8 @@ | ||
### Related projects | ||
* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. Much faster and lighter alternative to Inquirer, with all… [more](https://github.com/enquirer/enquirer) | [homepage](https://github.com/enquirer/enquirer "Intuitive, plugin-based prompt system for node.js. Much faster and lighter alternative to Inquirer, with all the same prompt types and more, but without the bloat.") | ||
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompt types for Enquirer. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompt types for 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.") | ||
### Contributing | ||
@@ -251,8 +282,8 @@ | ||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ | ||
_(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.)_ | ||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm install -g verb verb-generate-readme && verb | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
@@ -262,6 +293,6 @@ | ||
Install dev dependencies: | ||
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: | ||
```sh | ||
$ npm install -d && npm test | ||
$ npm install && npm test | ||
``` | ||
@@ -274,11 +305,11 @@ | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/enquirer/prompt-choices/blob/master/LICENSE). | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on August 30, 2016._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 12, 2017._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26078
14
587
300
- Removedisobject@^2.1.0
Updateddebug@^2.6.3
Updatedkind-of@^3.1.0
Updatedlazy-cache@^2.0.2
Updatedset-value@^0.4.3
Updatedterminal-paginator@^0.2.1