/*

Example:

{
label: 'group1',
options: [
{value: 'value1', text: 'description1'},
{value: 'value3', text: 'description3'}
]
}
331704
function getOptGroup(opts) {
  return {
    tag: 'optgroup',
    attrs: {
      disabled: opts.disabled,
      label: opts.label
    },
    children: opts.options.map(getOption),
    key: opts.label
  };
}
38800
def optgroups(self, name, value, attrs=None):
        """"""
        default = (None, [], 0)
        groups = [default]
        # We must add at least one 'selected' option or widget will show nothing.
        for v in value:
            if not v:
                continue
            if hasattr(self.choices, 'queryset'):
                item = self.choices.queryset.filter(id=v).first()
                if item:
                    label = item.name
                else:
                    label = force_text(v)
            else:
                label = force_text(v)
            subgroup = default[1]
            subgroup.append(self.create_option(
                name, v, label, True, 0,
                subindex=None, attrs=attrs,
            ))
        return groups
117337
def _group_kwargs_to_options(cls, obj, kwargs):
        ""
        groups = Options._option_groups
        if set(kwargs.keys()) - set(groups):
            raise Exception("Keyword options %s must be one of  %s" % (groups,
                            ','.join(repr(g) for g in groups)))
        elif not all(isinstance(v, dict) for v in kwargs.values()):
            raise Exception("The %s options must be specified using dictionary groups" %
                            ','.join(repr(k) for k in kwargs.keys()))

        # Check whether the user is specifying targets (such as 'Image.Foo')
        targets = [grp and all(k[0].isupper() for k in grp) for grp in kwargs.values()]
        if any(targets) and not all(targets):
            raise Exception("Cannot mix target specification keys such as 'Image' with non-target keywords.")
        elif not any(targets):
            # Not targets specified - add current object as target
            sanitized_group = util.group_sanitizer(obj.group)
            if obj.label:
                identifier = ('%s.%s.%s' % (
                    obj.__class__.__name__, sanitized_group,
                    util.label_sanitizer(obj.label)))
            elif  sanitized_group != obj.__class__.__name__:
                identifier = '%s.%s' % (obj.__class__.__name__, sanitized_group)
            else:
                identifier = obj.__class__.__name__

            options = {identifier:{grp:kws for (grp,kws) in kwargs.items()}}
        else:
            dfltdict = defaultdict(dict)
            for grp, entries in kwargs.items():
                for identifier, kws in entries.items():
                    dfltdict[identifier][grp] = kws
            options = dict(dfltdict)
        return options
300387
function (options, textFieldValue) {

            var selectedOptions = [];
            var trim = ariaUtilsString.trim;

            var inSplit = textFieldValue.split(this._separator);
            if (inSplit) {
                for (var i = 0, inSplitLen = aria.utils.Math.min(inSplit.length, this._maxOptions); i < inSplitLen; i++) {
                    for (var j = 0, optionsLen = options.length; j < optionsLen; j++) {
                        var key = trim(inSplit[i]);
                        options[j].label = options[j].label + "";
                        options[j].value = options[j].value + "";
                        key = key + "";

                        if ((trim(options[j].label.toLowerCase()) == key.toLowerCase() || trim(options[j].value.toLowerCase()) == key.toLowerCase())
                                && !ariaUtilsArray.contains(selectedOptions, options[j].value)
                                && !options[j].disabled) {
                            selectedOptions.push(options[j].value);
                        }
                    }
                }

            }

            return selectedOptions;
        }
1101392
function getOptionLabel(option, labelKey) {
  let optionLabel;

  if (typeof option === 'string') {
    optionLabel = option;
  }

  if (isPlainObject(option)) {
    if (typeof labelKey === 'string') {
      optionLabel = option[labelKey];
    } else if (isFunction(labelKey)) {
      optionLabel = labelKey(option);
    }
  }

  invariant(
    typeof optionLabel === 'string',
    'One or more options does not have a valid label string. Check the ' +
    '`labelKey` prop to ensure that it matches the correct option key and ' +
    'provides a string for filtering and display.'
  );

  return optionLabel;
}
961078
def choose_labels(alternatives):
    
    if not alternatives:
        raise ValueError

    if not isinstance(alternatives, list):
        raise TypeError

    choice_map = OrderedDict(
        ('{}'.format(i), value) for i, value in enumerate(alternatives, 1)
    )
    # prepend a termination option
    input_terminator = '0'
    choice_map.update({input_terminator: '<done>'})
    choice_map.move_to_end('0', last=False)

    choice_indexes = choice_map.keys()

    choice_lines = ['{} - {}'.format(*c) for c in choice_map.items()]
    prompt = '\n'.join(
        (
            'Select labels:',
            '\n'.join(choice_lines),
            'Choose from {}'.format(', '.join(choice_indexes)),
        )
    )

    user_choices = set()
    user_choice = None

    while not user_choice == input_terminator:
        if user_choices:
            note('Selected labels: [{}]'.format(', '.join(user_choices)))

        user_choice = click.prompt(
            prompt, type=click.Choice(choice_indexes), default=input_terminator
        )
        done = user_choice == input_terminator
        new_selection = user_choice not in user_choices
        nothing_selected = not user_choices

        if not done and new_selection:
            user_choices.add(choice_map[user_choice])

        if done and nothing_selected:
            error('Please select at least one label')
            user_choice = None

    return user_choices
1140312
function(opts) {
			var i, n, options, label, self = this;
			opts = opts || {};
	
			if (self.tagType === TAG_SELECT) {
				options = [];
				for (i = 0, n = self.items.length; i < n; i++) {
					label = self.options[self.items[i]][self.settings.labelField] || '';
					options.push('<option value="' + escape_html(self.items[i]) + '" selected="selected">' + escape_html(label) + '</option>');
				}
				if (!options.length && !this.$input.attr('multiple')) {
					options.push('<option value="" selected="selected"></option>');
				}
				self.$input.html(options.join(''));
			} else {
				self.$input.val(self.getValue());
				self.$input.attr('value',self.$input.val());
			}
	
			if (self.isSetup) {
				if (!opts.silent) {
					self.trigger('change', self.$input.val());
				}
			}
		}
1235687
def optgroups(self, name, value, attrs=None):
        """"""
        default = (None, [], 0)
        groups = [default]
        has_selected = False
        selected_choices = {str(v) for v in value}
        if not self.is_required and not self.allow_multiple_selected:
            default[1].append(self.create_option(name, '', '', False, 0))
        if not isinstance(self.choices, ModelChoiceIterator):
            return super(ModelSelect2Mixin, self).optgroups(name, value, attrs=attrs)
        selected_choices = {
            c for c in selected_choices
            if c not in self.choices.field.empty_values
        }
        field_name = self.choices.field.to_field_name or 'pk'
        query = Q(**{'%s__in' % field_name: selected_choices})
        for obj in self.choices.queryset.filter(query):
            option_value = self.choices.choice(obj)[0]
            option_label = self.label_from_instance(obj)

            selected = (
                str(option_value) in value and
                (has_selected is False or self.allow_multiple_selected)
            )
            if selected is True and has_selected is False:
                has_selected = True
            index = len(default[1])
            subgroup = default[1]
            subgroup.append(self.create_option(name, option_value, option_label, selected_choices, index))
        return groups
122884
def form_group(options = {})
      bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))

      label_options = bootstrap.label.clone
      label_text = label_options.delete(:text)

      label =
        if label_text.present?
          if bootstrap.horizontal?
            add_css_class!(label_options, "col-form-label")
            add_css_class!(label_options, bootstrap.label_col_class)
            add_css_class!(label_options, bootstrap.label_align_class)
          elsif bootstrap.inline?
            add_css_class!(label_options, bootstrap.inline_margin_class)
          end

          content_tag(:label, label_text, label_options)
        end

      form_group_class = "form-group"
      form_group_class += " row"      if bootstrap.horizontal?
      form_group_class += " mr-sm-2"  if bootstrap.inline?

      content_tag(:div, class: form_group_class) do
        content = "".html_safe
        content << label if label.present?
        content << draw_control_column(bootstrap, offset: label.blank?) do
          yield
        end
      end
    end
633697
function(idx, label, opt) {

        var labels = this.labels();

        idx = (isFinite(idx) && idx !== null) ? (idx | 0) : 0;
        if (idx < 0) idx = labels.length + idx;

        // getter
        if (arguments.length <= 1) return this.prop(['labels', idx]);
        // setter
        return this.prop(['labels', idx], label, opt);
    }
260956
function (items) {
		
			var i, length;
		
			// remove previous <option>s nodes
			while (this.el.childNodes.length > 0) {
				this.el.removeChild(this.el.childNodes[0]);
			}
		
			// add new options
			for (i = 0, length = items.length; i < length ; i += 1) {
				this.addChoice({ value: items[i][this.options.valueKey], label: items[i][this.options.labelKey] });
			}
		}
1225290
function parseEntities(value, options) {
  var settings = {}
  var option
  var key

  if (!options) {
    options = {}
  }

  for (key in defaults) {
    option = options[key]
    settings[key] =
      option === null || option === undefined ? defaults[key] : option
  }

  if (settings.position.indent || settings.position.start) {
    settings.indent = settings.position.indent || []
    settings.position = settings.position.start
  }

  return parse(value, settings)
}
227066
function getOptionLabel(option, labelKey) {
  if (option.paginationOption || option.customOption) {
    return option[getStringLabelKey(labelKey)];
  }

  let optionLabel;

  if (typeof option === 'string') {
    optionLabel = option;
  }

  if (typeof labelKey === 'function') {
    // This overwrites string options, but we assume the consumer wants to do
    // something custom if `labelKey` is a function.
    optionLabel = labelKey(option);
  } else if (typeof labelKey === 'string' && isPlainObject(option)) {
    optionLabel = option[labelKey];
  }

  invariant(
    typeof optionLabel === 'string',
    'One or more options does not have a valid label string. Check the ' +
    '`labelKey` prop to ensure that it matches the correct option key and ' +
    'provides a string for filtering and display.'
  );

  return optionLabel;
}
410195
def parse_labels(labels_str):
    
    if not _LABELS_RE.match(labels_str):
        return None
    labels = {}
    for kv in _KV_RE.finditer(labels_str):
        gd = kv.groupdict()
        key = unquote(gd['key'])
        if key in labels:
            logger.warning('Duplicate label key "%s"', key)
        labels[key] = unquote(gd['val'])
    return labels
753079
function(value, attr, values, model) {
        if(!_.include(values, value)){
          return this.format(defaultMessages.oneOf, this.formatLabel(attr, model), values.join(', '));
        }
      }
694799
function() {
		this._groups = [];
		var group_labels = this.timescale.getGroupLabels();

		if (group_labels) {
			this.options.has_groups = true;
			for (var i = 0; i < group_labels.length; i++) {
				this._createGroup(group_labels[i]);
			}
		}

	}
1237363
def trl(label, desc = "", tokens = {}, options = {})
      tr(label, desc, tokens, options.merge(:skip_decorations => true))
    end