diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/inquirer/lib/objects')
3 files changed, 181 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choice.js b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choice.js new file mode 100644 index 0000000000..51affac6dc --- /dev/null +++ b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choice.js @@ -0,0 +1,35 @@ +'use strict'; +var _ = require('lodash'); + +/** + * Choice object + * Normalize input as choice object + * @constructor + * @param {String|Object} val Choice value. If an object is passed, it should contains + * at least one of `value` or `name` property + */ + +var Choice = module.exports = function (val, answers) { + // Don't process Choice and Separator object + if (val instanceof Choice || val.type === 'separator') { + return val; + } + + if (_.isString(val)) { + this.name = val; + this.value = val; + this.short = 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; + } +}; diff --git a/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choices.js b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choices.js new file mode 100644 index 0000000000..41a36293cd --- /dev/null +++ b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/choices.js @@ -0,0 +1,112 @@ +'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 + */ + +var Choices = module.exports = function (choices, answers) { + this.choices = choices.map(function (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(function (item) { + return !item.disabled; + }); + + Object.defineProperty(this, 'length', { + get: function () { + return this.choices.length; + }, + set: function (val) { + this.choices.length = val; + } + }); + + Object.defineProperty(this, 'realLength', { + get: function () { + return this.realChoices.length; + }, + set: function () { + 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 + */ + +Choices.prototype.getChoice = function (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 + */ + +Choices.prototype.get = function (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 + */ + +Choices.prototype.where = function (whereClause) { + return _.filter(this.realChoices, whereClause); +}; + +/** + * Pluck a particular key from the choices + * @param {String} propertyName Property name to select + * @return {Array} Selected properties + */ + +Choices.prototype.pluck = function (propertyName) { + return _.map(this.realChoices, propertyName); +}; + +// Expose usual Array methods +Choices.prototype.indexOf = function () { + return this.choices.indexOf.apply(this.choices, arguments); +}; +Choices.prototype.forEach = function () { + return this.choices.forEach.apply(this.choices, arguments); +}; +Choices.prototype.filter = function () { + return this.choices.filter.apply(this.choices, arguments); +}; +Choices.prototype.find = function (func) { + return _.find(this.choices, func); +}; +Choices.prototype.push = function () { + var objs = _.map(arguments, function (val) { + return new Choice(val); + }); + this.choices.push.apply(this.choices, objs); + this.realChoices = this.choices.filter(Separator.exclude); + return this.choices; +}; diff --git a/tools/node_modules/eslint/node_modules/inquirer/lib/objects/separator.js b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/separator.js new file mode 100644 index 0000000000..abfaef17f2 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/inquirer/lib/objects/separator.js @@ -0,0 +1,34 @@ +'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) + */ + +var Separator = module.exports = function (line) { + this.type = 'separator'; + this.line = chalk.dim(line || new Array(15).join(figures.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'; +}; + +/** + * Stringify separator + * @return {String} the separator display string + */ + +Separator.prototype.toString = function () { + return this.line; +}; |