diff options
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects')
3 files changed, 207 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choice.js b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choice.js new file mode 100644 index 00000000..7dc88d67 --- /dev/null +++ b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choice.js @@ -0,0 +1,43 @@ +'use strict'; +const _ = { + isString: require('lodash/isString'), + isNumber: require('lodash/isNumber'), + extend: require('lodash/extend'), + isFunction: require('lodash/isFunction'), +}; + +/** + * 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; + } + } +}; diff --git a/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choices.js b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choices.js new file mode 100644 index 00000000..917b9196 --- /dev/null +++ b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/choices.js @@ -0,0 +1,127 @@ +'use strict'; +const assert = require('assert'); +const _ = { + isNumber: require('lodash/isNumber'), + filter: require('lodash/filter'), + map: require('lodash/map'), + find: require('lodash/find'), +}; +const Separator = require('./separator'); +const 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(...args) { + return this.choices.indexOf(...args); + } + + forEach(...args) { + return this.choices.forEach(...args); + } + + filter(...args) { + return this.choices.filter(...args); + } + + reduce(...args) { + return this.choices.reduce(...args); + } + + find(func) { + return _.find(this.choices, func); + } + + push(...args) { + const objs = _.map(args, (val) => new Choice(val)); + this.choices.push(...objs); + this.realChoices = this.choices + .filter(Separator.exclude) + .filter((item) => !item.disabled); + return this.choices; + } +}; diff --git a/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/separator.js b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/separator.js new file mode 100644 index 00000000..c7708628 --- /dev/null +++ b/sandbox/testAppNevena/Front/node_modules/inquirer/lib/objects/separator.js @@ -0,0 +1,37 @@ +'use strict'; +const chalk = require('chalk'); +const 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; |