1 | 'use strict';
|
2 | const _ = {
|
3 | isString: require('lodash/isString'),
|
4 | isNumber: require('lodash/isNumber'),
|
5 | extend: require('lodash/extend'),
|
6 | isFunction: require('lodash/isFunction'),
|
7 | };
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = class Choice {
|
18 | constructor(val, answers) {
|
19 |
|
20 | if (val instanceof Choice || val.type === 'separator') {
|
21 |
|
22 | return val;
|
23 | }
|
24 |
|
25 | if (_.isString(val) || _.isNumber(val)) {
|
26 | this.name = String(val);
|
27 | this.value = val;
|
28 | this.short = String(val);
|
29 | } else {
|
30 | _.extend(this, val, {
|
31 | name: val.name || val.value,
|
32 | value: 'value' in val ? val.value : val.name,
|
33 | short: val.short || val.name || val.value,
|
34 | });
|
35 | }
|
36 |
|
37 | if (_.isFunction(val.disabled)) {
|
38 | this.disabled = val.disabled(answers);
|
39 | } else {
|
40 | this.disabled = val.disabled;
|
41 | }
|
42 | }
|
43 | };
|