<commit_before>/**
 * Determines whether the element is in the area of the viewport or not.
 * @param  {HTMLElement} elm - HTML element to test
 * @param  {Number} [threshold = 0] - The distance to the edge of the viwport before
 *                                    the element is no longer visible in the viewport area
 *
 * @return {Boolean|Object} - If the element is in the viewport area it returns true,
 *                            otherwise it returns an object with indications of
 *                            where the element is compared to the viewport area
 */
export default function inView(elm, threshold = 0) {
  const rect = elm.getBoundingClientRect();
  const vpWidth = window.innerWidth;
  const vpHeight = window.innerHeight;

  // Determine if the element is on screen
  const aboveView = rect.bottom - threshold < 0;
  const belowView = rect.top - vpHeight + threshold >= 0;
  const leftOfView = rect.right - threshold < 0;
  const rightOfView = rect.left - vpWidth + threshold >= 0;

  // If it is on screen return true
  if(!aboveView && !belowView && !leftOfView && !rightOfView) { return true; }

  // Otherwise return an object saying where the element is compared to the viewport
  return { aboveView, belowView, leftOfView, rightOfView };
}
<commit_msg>Add DOM check to 'inView' script<commit_after>import isDOMElement from './isDOMElement';

/**
 * Determines whether the element is in the area of the viewport or not.
 * @param  {HTMLElement} elm - HTML element to test
 * @param  {Number} [threshold = 0] - The distance to the edge of the viwport before
 *                                    the element is no longer visible in the viewport area
 *
 * @return {Boolean|Object} - If the element is in the viewport area it returns true,
 *                            otherwise it returns an object with indications of
 *                            where the element is compared to the viewport area
 */
export default function inView(elm, threshold = 0) {
  if(!isDOMElement(elm)) { return false; }

  const rect = elm.getBoundingClientRect();
  const vpWidth = window.innerWidth;
  const vpHeight = window.innerHeight;

  // Determine if the element is on screen
  const aboveView = rect.bottom - threshold < 0;
  const belowView = rect.top - vpHeight + threshold >= 0;
  const leftOfView = rect.right - threshold < 0;
  const rightOfView = rect.left - vpWidth + threshold >= 0;

  // If it is on screen return true
  if(!aboveView && !belowView && !leftOfView && !rightOfView) { return true; }

  // Otherwise return an object saying where the element is compared to the viewport
  return { aboveView, belowView, leftOfView, rightOfView };
}

{'fraction_non_alphanumeric': 0.08180799402316026, 'fraction_numerical': 0.0044826298094882335, 'mean_word_length': 2.798581560283688, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5464599', 'n_tokens_mistral': 748, 'n_tokens_neox': 715, 'n_words': 309}