<commit_before>angular
  .module('lnPatterns')
  .factory('lnOGravityFormDataParser', lnOGravityFormDataParser);

/*@ngInject*/
function lnOGravityFormDataParser(isValidParameterFilter) {

  // Public API
  //

  return {
    parse: parse
  };

  function parse(inputs) {
    var _data = {
      'input_values': {}
    };

    var checkboxLists = {};

    if (!inputs || !inputs.length) {
      return _data;
    }

    for (var i = 0; i < inputs.length; i++) {
      var input = inputs[i];
      var name;
      var value;

      if (isValidParameterFilter(input.name)) {

        switch (input.type) {
          case 'radio':
            if (isUnselectedRadioButton(input)) {
              continue;
            }
            break;
          case 'checkbox':
            name = getCheckboxListGroupName(input);
            if (angular.isDefined(checkboxLists[name])) {
              continue;
            }
            checkboxLists[name] = getCheckboxList(name, inputs);
            value = checkboxLists[name];
            break;
          case 'select':
          case 'select-multiple':
            name = input.name;
            value = input.value;
            if (input.multiple) {
              value = angular.element(input).val();
            }
            break;
          default:
            name = input.name;
            value = input.value;
        }

        _data.input_values[name] = value;
      }
    }

    return _data;
  }


  // Internal
  //

  function isUnselectedRadioButton(input) {
    return (input.type === 'radio' && !input.checked);
  }

  function getCheckboxListGroupName(input) {
    return input.name.substring(0, input.name.indexOf('.'));
  }

  function getCheckboxList(groupName, inputs) {
    var _list = inputs.filter(function (item) {
      return item.name.indexOf(groupName) > -1 && item.checked;
    });

    return getListValues(_list);
  }

  function getListValues(list) {
    var _values = [];
    for (var i = 0; i < list.length; i++) {
      _values.push(list[i].value);
    }
    return _values;
  }

}
<commit_msg>reduce complexity in form data parser<commit_after>angular
  .module('lnPatterns')
  .factory('lnOGravityFormDataParser', lnOGravityFormDataParser);

/*@ngInject*/
function lnOGravityFormDataParser(isValidParameterFilter) {

  // Public API
  //

  return {
    parse: parse
  };

  function parse(inputs) {
    var _data = {
      'input_values': {}
    };

    var checkboxLists = {};

    if (!inputs || !inputs.length) {
      return _data;
    }

    for (var i = 0; i < inputs.length; i++) {
      var input = inputs[i];
      var name;
      var value;

      if (!isValidParameterFilter(input.name)) {
        continue;
      }

      if (isUnselectedRadioButton(input)) {
        continue;
      }

      switch (input.type) {
        case 'checkbox':
          name = getCheckboxListGroupName(input);
          if (angular.isDefined(checkboxLists[name])) {
            continue;
          }
          checkboxLists[name] = getCheckboxList(name, inputs);
          value = checkboxLists[name];
          break;
        case 'select-multiple':
          name = input.name;
          if (input.multiple) {
            value = angular.element(input).val();
          }
          break;
        default:
          name = input.name;
          value = input.value;
      }

      _data.input_values[name] = value;
    }

    return _data;
  }


  // Internal
  //

  function isUnselectedRadioButton(input) {
    return (input.type === 'radio' && !input.checked);
  }

  function getCheckboxListGroupName(input) {
    return input.name.substring(0, input.name.indexOf('.'));
  }

  function getCheckboxList(groupName, inputs) {
    var _list = inputs.filter(function (item) {
      return item.name.indexOf(groupName) > -1 && item.checked;
    });

    return getListValues(_list);
  }

  function getListValues(list) {
    var _values = [];
    for (var i = 0; i < list.length; i++) {
      _values.push(list[i].value);
    }
    return _values;
  }

}

{'fraction_non_alphanumeric': 0.12701562887620937, 'fraction_numerical': 0.0019846192011907715, 'mean_word_length': 2.0157068062827226, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587276', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1203, 'n_words': 243}