<commit_before>import lodashGet from 'lodash/get'

import isPopulatedArray from 'js/utils/isPopulatedArray'

/**
 * Quick function to help find react components independent of ordering.
 * @param  {ReactElement} component React component instance.
 * @param  {String} keypath Could be 'type' or 'props.legend'.
 * @param  {String} val The value to check against.
 * @return {ReactElement} The found element, or undefined.
 */
const findChild = (component, keypath, val) => {
  let children = lodashGet(component, 'props.children', [])
  if (!isPopulatedArray(children)) {
    return undefined
  }
  return component.props.children.find(elem => {
    return lodashGet(elem, keypath) === val
  })
}

export default findChild<commit_msg>[#36] Support nested arrays of children, for nicer rendering syntax.<commit_after>import lodashGet from 'lodash/get'
import isArray from 'lodash/isArray'

import isPopulatedArray from 'js/utils/isPopulatedArray'

/**
 * Quick function to help find react components independent of ordering.
 * @param  {ReactElement} component React component instance.
 * @param  {String} keypath Could be 'type' or 'props.legend'.
 * @param  {String} val The value to check against.
 * @return {ReactElement} The found element, or undefined.
 */
const findChild = (component, keypath, val) => {
  let children = lodashGet(component, 'props.children', [])
  if (!isPopulatedArray(children)) {
    return undefined
  }
  return component.props.children.find(elem => {
    // When rendering, we can nest arrays of components.
    if (isArray(elem)) {
      return findChild({
        props: {
          children: elem
        }
      }, keypath, val)
    }
    // Normal element child.
    return lodashGet(elem, keypath) === val
  })
}

export default findChild
{'fraction_non_alphanumeric': 0.11198649409116489, 'fraction_numerical': 0.0011254924029262803, 'mean_word_length': 3.844686648501362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '741664', 'n_tokens_mistral': 520, 'n_tokens_neox': 504, 'n_words': 170}