<commit_before>/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import objectAssign from "./object_assign";

/**
 * Check if an item is an object
 * @param item
 * @returns {boolean}
 */
function isObject(item: any) : boolean {
  return (item !== null
          && item !== undefined
          && typeof item === "object"
          && !Array.isArray(item));
}

type IDeepPartial<T> = {
  [P in keyof T]?: IDeepPartial<T[P]> ;
};

/**
 * Deeply merge nested objects
 * @param target
 * @param sources
 * @returns output : merged object
 */
export default function deepMerge<T>(target: T, ...sources: Array<IDeepPartial<T>>): T {
  if (sources.length === 0) {
    return target;
  }
  const source = sources.shift() as IDeepPartial<T>;
  if (isObject(target) && isObject(source)) {
    for (const key in source) {
      if (isObject(source[key])) {
        if (target[key] === undefined) {
          objectAssign(target, { [key]: {} });
        }
        const newTarget = target[key];
        deepMerge(newTarget, source[key] as IDeepPartial<typeof newTarget>);
      } else {<commit_msg>⚡️ redundant check in deep_merge removed<commit_after>/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import objectAssign from "./object_assign";

/**
 * Check if an item is an object
 * @param item
 * @returns {boolean}
 */
function isObject(item: any) : boolean {
  return (item !== null
          && item !== undefined
          && !Array.isArray(item));
}

type IDeepPartial<T> = {
  [P in keyof T]?: IDeepPartial<T[P]> ;
};

/**
 * Deeply merge nested objects
 * @param target
 * @param sources
 * @returns output : merged object
 */
export default function deepMerge<T>(target: T, ...sources: Array<IDeepPartial<T>>): T {
  if (sources.length === 0) {
    return target;
  }
  const source = sources.shift() as IDeepPartial<T>;
  if (isObject(target) && isObject(source)) {
    for (const key in source) {
      if (isObject(source[key])) {
        if (target[key] === undefined) {
          objectAssign(target, { [key]: {} });
        }
        const newTarget = target[key];
        deepMerge(newTarget, source[key] as IDeepPartial<typeof newTarget>);
      } else {
{'fraction_non_alphanumeric': 0.15834970530451867, 'fraction_numerical': 0.0007858546168958742, 'mean_word_length': 3.2504173622704506, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7185919', 'n_tokens_mistral': 806, 'n_tokens_neox': 799, 'n_words': 198}