<commit_before>import { isArrayLike } from './isArrayLike';
import { typeOf } from './typeOf';

/**
 * Checks if value is an empty object, collection, map, or set.
 *
 * Objects are considered empty if
 * they have no own enumerable string keyed properties.
 *
 * Array-like values such as arguments objects, arrays,
 * buffers, strings, or jQuery-like collections are
 * considered empty if they have a length of 0.
 *
 * Similarly, maps and sets are considered empty
 * if they have a size of 0.
 *
 * Any other type of value will always result in true (empty)
 *
 * @export
 * @param {*} input
 * @returns {boolean}
 */

export function isEmpty(input: any): boolean {

  // null and undefined => true
  if (input == null) return true;

  const type: string = typeOf(input);

  // for array like data, check if the length is zero
  if (isArrayLike(input)
    && (type.search(/(float(32|64)|(int|uint)(8|16|32)|uint8clamped|string|array|buffer|arguments)/) !== -1
      || typeOf(input.slice) === 'function')) {

    return !input.length;

  }

  // for map and set, check if size is zero
  if (type.search(/(map|set)/) !== -1) return !input.size;

  // for object, check the property chain containing more than just constructor
  for (const key in input) {
    if (input.hasOwnProperty(key) && key !== 'constructor') {
      return false;
    }
  }

  // anything else will result in true (empty)
  return true;

}<commit_msg>ref: isEmpty()<commit_after>import { isArrayLike } from './isArrayLike';
import { typeOf } from './typeOf';

/**
 * Checks if value is an empty object, collection, map, or set.
 *
 * Objects are considered empty if
 * they have no own enumerable string keyed properties.
 *
 * Array-like values such as arguments objects, arrays,
 * buffers, strings, or jQuery-like collections are
 * considered empty if they have a length of 0.
 *
 * Similarly, maps and sets are considered empty
 * if they have a size of 0.
 *
 * Any other type of value will always result in true (empty)
 *
 * @export
 * @param {*} input
 * @returns {boolean}
 */

export function isEmpty(input: any): boolean {

  // null and undefined => true
  if (input == null) return true;

  const type: string = typeOf(input);

  if (isArrayLike(input)
    && (type.search(/(float(32|64)|(int|uint)(8|16|32)|uint8clamped|string|array|buffer|arguments)/) !== -1
      || typeOf(input.slice) === 'function')) {

    // for array like data, check if the length is zero
    return !input.length;

  } else if (type.search(/(map|set)/) !== -1) {

    // for map and set, check if size is zero
    return !input.size;

  } else {
    for (const key in input) {
      if (input.hasOwnProperty(key) && key !== 'constructor') {
        // for object, check the property chain (constructor does not count)
        return false;
      }
    }

  }

  // anything else will result in true (empty)
  return true;

}
{'fraction_non_alphanumeric': 0.12962322848254407, 'fraction_numerical': 0.00967853439336329, 'mean_word_length': 3.1942028985507247, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5747411', 'n_tokens_mistral': 887, 'n_tokens_neox': 860, 'n_words': 332}