Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

choice.js 921B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var _ = require('lodash');
  3. /**
  4. * Choice object
  5. * Normalize input as choice object
  6. * @constructor
  7. * @param {String|Object} val Choice value. If an object is passed, it should contains
  8. * at least one of `value` or `name` property
  9. */
  10. module.exports = class Choice {
  11. constructor(val, answers) {
  12. // Don't process Choice and Separator object
  13. if (val instanceof Choice || val.type === 'separator') {
  14. return val;
  15. }
  16. if (_.isString(val)) {
  17. this.name = val;
  18. this.value = val;
  19. this.short = val;
  20. } else {
  21. _.extend(this, val, {
  22. name: val.name || val.value,
  23. value: 'value' in val ? val.value : val.name,
  24. short: val.short || val.name || val.value
  25. });
  26. }
  27. if (_.isFunction(val.disabled)) {
  28. this.disabled = val.disabled(answers);
  29. } else {
  30. this.disabled = val.disabled;
  31. }
  32. }
  33. };