Every new change
This commit is contained in:
38
node_modules/inquirer/lib/objects/choice.js
generated
vendored
Normal file
38
node_modules/inquirer/lib/objects/choice.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
var _ = require('lodash');
|
||||
|
||||
/**
|
||||
* Choice object
|
||||
* Normalize input as choice object
|
||||
* @constructor
|
||||
* @param {Number|String|Object} val Choice value. If an object is passed, it should contains
|
||||
* at least one of `value` or `name` property
|
||||
*/
|
||||
|
||||
module.exports = class Choice {
|
||||
constructor(val, answers) {
|
||||
// Don't process Choice and Separator object
|
||||
if (val instanceof Choice || val.type === 'separator') {
|
||||
// eslint-disable-next-line no-constructor-return
|
||||
return val;
|
||||
}
|
||||
|
||||
if (_.isString(val) || _.isNumber(val)) {
|
||||
this.name = String(val);
|
||||
this.value = val;
|
||||
this.short = String(val);
|
||||
} else {
|
||||
_.extend(this, val, {
|
||||
name: val.name || val.value,
|
||||
value: 'value' in val ? val.value : val.name,
|
||||
short: val.short || val.name || val.value
|
||||
});
|
||||
}
|
||||
|
||||
if (_.isFunction(val.disabled)) {
|
||||
this.disabled = val.disabled(answers);
|
||||
} else {
|
||||
this.disabled = val.disabled;
|
||||
}
|
||||
}
|
||||
};
|
118
node_modules/inquirer/lib/objects/choices.js
generated
vendored
Normal file
118
node_modules/inquirer/lib/objects/choices.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
var _ = require('lodash');
|
||||
var Separator = require('./separator');
|
||||
var Choice = require('./choice');
|
||||
|
||||
/**
|
||||
* Choices collection
|
||||
* Collection of multiple `choice` object
|
||||
* @constructor
|
||||
* @param {Array} choices All `choice` to keep in the collection
|
||||
*/
|
||||
|
||||
module.exports = class Choices {
|
||||
constructor(choices, answers) {
|
||||
this.choices = choices.map(val => {
|
||||
if (val.type === 'separator') {
|
||||
if (!(val instanceof Separator)) {
|
||||
val = new Separator(val.line);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
return new Choice(val, answers);
|
||||
});
|
||||
|
||||
this.realChoices = this.choices
|
||||
.filter(Separator.exclude)
|
||||
.filter(item => !item.disabled);
|
||||
|
||||
Object.defineProperty(this, 'length', {
|
||||
get() {
|
||||
return this.choices.length;
|
||||
},
|
||||
set(val) {
|
||||
this.choices.length = val;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'realLength', {
|
||||
get() {
|
||||
return this.realChoices.length;
|
||||
},
|
||||
set() {
|
||||
throw new Error('Cannot set `realLength` of a Choices collection');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a valid choice from the collection
|
||||
* @param {Number} selector The selected choice index
|
||||
* @return {Choice|Undefined} Return the matched choice or undefined
|
||||
*/
|
||||
|
||||
getChoice(selector) {
|
||||
assert(_.isNumber(selector));
|
||||
return this.realChoices[selector];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a raw element from the collection
|
||||
* @param {Number} selector The selected index value
|
||||
* @return {Choice|Undefined} Return the matched choice or undefined
|
||||
*/
|
||||
|
||||
get(selector) {
|
||||
assert(_.isNumber(selector));
|
||||
return this.choices[selector];
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the valid choices against a where clause
|
||||
* @param {Object} whereClause Lodash `where` clause
|
||||
* @return {Array} Matching choices or empty array
|
||||
*/
|
||||
|
||||
where(whereClause) {
|
||||
return _.filter(this.realChoices, whereClause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluck a particular key from the choices
|
||||
* @param {String} propertyName Property name to select
|
||||
* @return {Array} Selected properties
|
||||
*/
|
||||
|
||||
pluck(propertyName) {
|
||||
return _.map(this.realChoices, propertyName);
|
||||
}
|
||||
|
||||
// Expose usual Array methods
|
||||
indexOf() {
|
||||
return this.choices.indexOf.apply(this.choices, arguments);
|
||||
}
|
||||
|
||||
forEach() {
|
||||
return this.choices.forEach.apply(this.choices, arguments);
|
||||
}
|
||||
|
||||
filter() {
|
||||
return this.choices.filter.apply(this.choices, arguments);
|
||||
}
|
||||
|
||||
find(func) {
|
||||
return _.find(this.choices, func);
|
||||
}
|
||||
|
||||
push() {
|
||||
var objs = _.map(arguments, val => new Choice(val));
|
||||
this.choices.push.apply(this.choices, objs);
|
||||
this.realChoices = this.choices
|
||||
.filter(Separator.exclude)
|
||||
.filter(item => !item.disabled);
|
||||
return this.choices;
|
||||
}
|
||||
};
|
37
node_modules/inquirer/lib/objects/separator.js
generated
vendored
Normal file
37
node_modules/inquirer/lib/objects/separator.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
var chalk = require('chalk');
|
||||
var figures = require('figures');
|
||||
|
||||
/**
|
||||
* Separator object
|
||||
* Used to space/separate choices group
|
||||
* @constructor
|
||||
* @param {String} line Separation line content (facultative)
|
||||
*/
|
||||
|
||||
class Separator {
|
||||
constructor(line) {
|
||||
this.type = 'separator';
|
||||
this.line = chalk.dim(line || new Array(15).join(figures.line));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify separator
|
||||
* @return {String} the separator display string
|
||||
*/
|
||||
toString() {
|
||||
return this.line;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function returning false if object is a separator
|
||||
* @param {Object} obj object to test against
|
||||
* @return {Boolean} `false` if object is a separator
|
||||
*/
|
||||
|
||||
Separator.exclude = function(obj) {
|
||||
return obj.type !== 'separator';
|
||||
};
|
||||
|
||||
module.exports = Separator;
|
Reference in New Issue
Block a user