<commit_before>import _ from 'lodash'

const form2obj = (form, options) => {
  const { elements } = form

  const allProperties = _.chain(elements)
    .map('name')
    .compact()
    .uniq()
    .value()

  const _elements = _.pick(elements, allProperties)

  const test = {}

  _.each(_elements, (node, propName) => {
    if (_.isArrayLikeObject(node)) {
      _.each(node, (element, idx) => setValue(element, idx))
    } else {
      setValue(node)
    }
  })

  console.log(test)

  function setValue(element, elementIdx) {

    const { name, type, value, checked } = element

    const fieldName = elementIdx ? `${name}[${elementIdx}]` : name

    if (_.includes(['text'], type)) {
      value && _.set(test, fieldName, value)
    }

    if (_.includes(['number'], type)) {
      value && _.set(test, fieldName, parseInt(value))
    }

    if (_.includes(['radio'], type) && checked) {
      value && _.set(test, name, value)
    }

  }

  return test

}

export default form2obj<commit_msg>minor update<commit_after>import _ from 'lodash'

const form2obj = (form, options) => {
  const { elements } = form

  const allProperties = _.chain(elements)
    .map('name')
    .compact()
    .uniq()
    .value()

  const _elements = _.pick(elements, allProperties)

  const test = {}

  _.each(_elements, (node, propName) => {
    if (_.isArrayLikeObject(node)) {
      _.each(node, (element, idx) => setValue(element, idx + 1))
    } else {
      setValue(node)
    }
  })

  console.log(JSON.stringify(test, null, 4))

  function setValue(element, elementIdx) {

    const { name, type, value, checked } = element

    const fieldName = elementIdx ? `${name}[${elementIdx - 1}]` : name

    console.log(fieldName)

    if (_.includes(['text'], type)) {
      value && _.set(test, fieldName, value)
    }

    if (_.includes(['number'], type)) {
      value && _.set(test, fieldName, parseInt(value))
    }

    if (_.includes(['radio'], type) && checked) {
      value && _.set(test, name, value)
    }

    if (_.includes(['checkbox'], type)) {
      if (checked) {
        const existValues = _.defaultTo(_.get(test, name), [])
        value && _.set(test, name, _.concat(existValues, value))
      }
    }

  }

  return test

}

export default form2obj
{'fraction_non_alphanumeric': 0.16651904340124005, 'fraction_numerical': 0.003100088573959256, 'mean_word_length': 2.8158783783783785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4580994', 'n_tokens_mistral': 756, 'n_tokens_neox': 725, 'n_words': 173}