<commit_before>/**
 * focusableSelectors - froze array of strings
 *
 * Selectors for all HTML elements that are
 * "focusable" including HTML elements with
 * a tabindex applied.
 */
const focusableSelectors = Object.freeze([
  'input',
  'select',
  'a[href]',
  'textarea',
  'button',
  '[tabindex]'
]);

const getFocusableNodesInElement = el => {
  const focusableNodes = Array.prototype.slice.call(el.querySelectorAll(focusableSelectors.join(',')));

  return focusableNodes && focusableNodes.length ? focusableNodes.filter(node => {
    const nodeTabIndexAttr = parseInt(node.getAttribute('tabindex'), 10);
    const nodeTabIndex = isNaN(nodeTabIndexAttr) ? 0 : nodeTabIndexAttr;
    const nodeAriaHiddenAttr = node.getAttribute('aria-hidden') === 'true';

    return nodeTabIndex >= 0 && !nodeAriaHiddenAttr;
  }) : [];
};

const reconcileNodeArrays = (allFocusableNodes, childFocusableNodes) => {
  return allFocusableNodes.filter(node => {
    return childFocusableNodes.indexOf(node) === -1;
  });
};

const setNodeAttributes = (node, attributes) => {
  for (const key in attributes) {
    if (attributes.hasOwnProperty(key)) {
      node.setAttribute(key, attributes[key]);
    }
  }
};

module.exports = {
  focusableSelectors,
  getFocusableNodesInElement,
  reconcileNodeArrays,
  setNodeAttributes
};<commit_msg>Adds documentaiton comments to getFocusableNodesInElement<commit_after>/**
 * focusableSelectors - froze array of strings
 *
 * Selectors for all HTML elements that are
 * "focusable" including HTML elements with
 * a tabindex applied.
 */
const focusableSelectors = Object.freeze([
  'input',
  'select',
  'a[href]',
  'textarea',
  'button',
  '[tabindex]'
]);

/**
 * getFocusableNodesInElement
 *
 * Returns an array of DOM Nodes found within
 * the supplied DOM Node that are considered
 * focusable(based upon a query with the focusableSelectors)
 * and are not currently hidden via a -1 tabindex
 * or aria-hidden attribute.
 *
 * @param {DOM Node} el
 */
const getFocusableNodesInElement = el => {
  // querySelectorAll returns a nodeList so we have
  // to use Array.prototype.slice.call to convert it
  // to a normal array.
  const focusableNodes = Array.prototype.slice.call(el.querySelectorAll(focusableSelectors.join(',')));

  return focusableNodes && focusableNodes.length ? focusableNodes.filter(node => {
    // If a node doesn't have an existing tabindex
    // eg: buttons, links, inputs, etc...,
    // then we set the nodeTabIndex value to 0 to
    // ensure it passes the equality check of the
    // filter.
    const nodeTabIndexAttr = parseInt(node.getAttribute('tabindex'), 10);
    const nodeTabIndex = isNaN(nodeTabIndexAttr) ? 0 : nodeTabIndexAttr;

    // The getAttribute call returns a string so
    // we have to stritcly check for a string 'true'
    // or things no worky.
    const nodeAriaHiddenAttrValue = node.getAttribute('aria-hidden') === 'true';

    return nodeTabIndex >= 0 && !nodeAriaHiddenAttrValue;
  }) : [];
};

const reconcileNodeArrays = (allFocusableNodes, childFocusableNodes) => {
  return allFocusableNodes.filter(node => {
    return childFocusableNodes.indexOf(node) === -1;
  });
};

const setNodeAttributes = (node, attributes) => {
  for (const key in attributes) {
    if (attributes.hasOwnProperty(key)) {
      node.setAttribute(key, attributes[key]);
    }
  }
};

module.exports = {
  focusableSelectors,
  getFocusableNodesInElement,
  reconcileNodeArrays,
  setNodeAttributes
};
{'fraction_non_alphanumeric': 0.11935576646534368, 'fraction_numerical': 0.003451251078515962, 'mean_word_length': 4.0922401171303076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1335289', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1039, 'n_words': 279}