3 isString: require('lodash/isString'),
4 isNumber: require('lodash/isNumber'),
5 extend: require('lodash/extend'),
6 isFunction: require('lodash/isFunction'),
11 * Normalize input as choice object
13 * @param {Number|String|Object} val Choice value. If an object is passed, it should contains
14 * at least one of `value` or `name` property
17 module.exports = class Choice {
18 constructor(val, answers) {
19 // Don't process Choice and Separator object
20 if (val instanceof Choice || val.type === 'separator') {
21 // eslint-disable-next-line no-constructor-return
25 if (_.isString(val) || _.isNumber(val)) {
26 this.name = String(val);
28 this.short = String(val);
31 name: val.name || val.value,
32 value: 'value' in val ? val.value : val.name,
33 short: val.short || val.name || val.value,
37 if (_.isFunction(val.disabled)) {
38 this.disabled = val.disabled(answers);
40 this.disabled = val.disabled;