<commit_before>// =============================================================================
// Core.ts | Utility Functions
// (c) Mathigon
// =============================================================================


/** Object Map Interface. */
export type Obj<T> = {[key: string]: T};


/** Creates a random UID string of a given length. */
export function uid(n = 10) {
  return Math.random().toString(36).substr(2, n);
}


/** Executes a function or returns the default value. */
export function run<T, S>(val: T|((...args: S[]) => T), ...args: S[]) {
  if (val instanceof Function) return val(...args);
  return val;
}


/** Checks if x is strictly equal to any one of the following arguments. */
export function isOneOf<T>(x: T, ...values: T[]) {
  return values.includes(x);
}

/** Applies default keys to an object. Properties with value `undefined` or `null` will **not** be overwritten. */
export function applyDefaults<O extends Obj<unknown>, D extends Obj<unknown>>(obj: O, defaults: D) {
  for (const key of Object.keys(defaults)) {
    if (!Object.prototype.hasOwnProperty.call(obj, key)) (obj as Obj<unknown>)[key] = defaults[key];
  }
  return obj as O & D;
}


const defaultMerge = ((a: unknown[], b: unknown[]) => a.concat(b));

/** Deep extends obj1 with obj2, using a custom array merge function. */
export function deepExtend(obj1: any, obj2: any, arrayMergeFn = defaultMerge) {
  for (const i of Object.keys(obj2)) {
    if (i in obj1 && Array.isArray(obj1[i]) && Array.isArray(obj2[i])) {
      obj1[i] = arrayMergeFn(obj1[i], obj2[i]);
    } else if (i in obj1 && obj1[i] instanceof Object &&
               obj2[i] instanceof Object) {
      deepExtend(obj1[i], obj2[i]);<commit_msg>Remove applyDefaults method (which is the same as Object.assign)<commit_after>// =============================================================================
// Core.ts | Utility Functions
// (c) Mathigon
// =============================================================================


/** Object Map Interface. */
export type Obj<T> = {[key: string]: T};


/** Creates a random UID string of a given length. */
export function uid(n = 10) {
  return Math.random().toString(36).substr(2, n);
}


/** Executes a function or returns the default value. */
export function run<T, S>(val: T|((...args: S[]) => T), ...args: S[]) {
  if (val instanceof Function) return val(...args);
  return val;
}


/** Checks if x is strictly equal to any one of the following arguments. */
export function isOneOf<T>(x: T, ...values: T[]) {
  return values.includes(x);
}


const defaultMerge = ((a: unknown[], b: unknown[]) => a.concat(b));

/** Deep extends obj1 with obj2, using a custom array merge function. */
export function deepExtend(obj1: any, obj2: any, arrayMergeFn = defaultMerge) {
  for (const i of Object.keys(obj2)) {
    if (i in obj1 && Array.isArray(obj1[i]) && Array.isArray(obj2[i])) {
      obj1[i] = arrayMergeFn(obj1[i], obj2[i]);
    } else if (i in obj1 && obj1[i] instanceof Object &&
               obj2[i] instanceof Object) {
      deepExtend(obj1[i], obj2[i]);
{'fraction_non_alphanumeric': 0.25282896863886195, 'fraction_numerical': 0.013579049466537343, 'mean_word_length': 4.03089430894309, 'pattern_counts': {'":': 0, '<': 13, '<?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': '301343', 'n_tokens_mistral': 955, 'n_tokens_neox': 918, 'n_words': 311}