<commit_before>import { Settings } from '../interfaces/settings';

const assignBoolean = (target, source, token, defaultSettings) => {
  let param = source[token];
  if (typeof param === 'undefined') {
    return;
  }
  if (typeof param !== 'boolean') {
    console.warn(token + ' setting parse error, set it to ' + defaultSettings[token] + ' (default)');
    return;
  }
  target[token] = param;
  return true;
};

const assignNumeric = (target, source, token, defaultSettings, integer = false) => {
  let param = source[token];
  if (typeof param === 'undefined') {
    return;
  }
  if (typeof param !== 'number') {
    console.warn(token + ' setting parse error, set it to ' + defaultSettings[token] + ' (default)');
    return;
  }
  if (integer && parseInt(param.toString(), 10) !== param) {
    console.warn(token + ' setting parse error, set it to ' + defaultSettings[token] + ' (default)');
    return;
  }
  target[token] = param;
  return true;
};

const assignMinimalNumeric = (target, source, token, defaultSettings, minSettings, integer = false) => {
  if (assignNumeric(target, source, token, integer) !== true) {
    return;
  }
  if (target[token] < minSettings[token]) {
    console.warn(token + ' setting is less than minimum, set it to ' + minSettings[token]);
    target[token] = minSettings[token];
    return;
  }
  return true;
};

export const assignSettings = (targetObject, settings: Settings, defaultSettings, minSettings) => {
  Object.assign(this, defaultSettings);

  if (typeof settings === 'undefined') {
    return;
  }
  if (typeof settings !== 'object') {
    console.warn('settings is not an object, fallback to the defaults');
    return;
  }

  assignNumeric(targetObject, settings, 'startIndex', defaultSettings);
  assignMinimalNumeric(targetObject, settings, 'bufferSize', defaultSettings, minSettings, true);
  assignMinimalNumeric(targetObject, settings, 'padding', defaultSettings, minSettings);
  assignBoolean(targetObject, settings, 'infinite', defaultSettings);
  assignBoolean(targetObject, settings, 'horizontal', defaultSettings);

  // undocumented settings, for tests only
  assignBoolean(targetObject, settings, 'clipAfterFetchOnly', defaultSettings);
  assignBoolean(targetObject, settings, 'clipAfterScrollOnly', defaultSettings);
};<commit_msg>remove circular dependencies (2)<commit_after>const assignBoolean = (target, source, token, defaults) => {
  let param = source[token];
  if (typeof param === 'undefined') {
    return;
  }
  if (typeof param !== 'boolean') {
    console.warn(token + ' setting parse error, set it to ' + defaults[token] + ' (default)');
    return;
  }
  target[token] = param;
  return true;
};

const assignNumeric = (target, source, token, defaults, integer = false) => {
  let param = source[token];
  if (typeof param === 'undefined') {
    return;
  }
  if (typeof param !== 'number') {
    console.warn(token + ' setting parse error, set it to ' + defaults[token] + ' (default)');
    return;
  }
  if (integer && parseInt(param.toString(), 10) !== param) {
    console.warn(token + ' setting parse error, set it to ' + defaults[token] + ' (default)');
    return;
  }
  target[token] = param;
  return true;
};

const assignMinimalNumeric = (target, source, token, defaults, minSettings, integer = false) => {
  if (assignNumeric(target, source, token, defaults, integer) !== true) {
    return;
  }
  if (target[token] < minSettings[token]) {
    console.warn(token + ' setting is less than minimum, set it to ' + minSettings[token]);
    target[token] = minSettings[token];
    return;
  }
  return true;
};

export const assignSettings = (target, settings, defaults, minSettings) => {
  Object.assign(target, defaults);

  if (typeof settings === 'undefined') {
    return;
  }
  if (typeof settings !== 'object') {
    console.warn('settings is not an object, fallback to the defaults');
    return;
  }

  assignNumeric(target, settings, 'startIndex', defaults);
  assignMinimalNumeric(target, settings, 'bufferSize', defaults, minSettings, true);
  assignMinimalNumeric(target, settings, 'padding', defaults, minSettings);
  assignBoolean(target, settings, 'infinite', defaults);
  assignBoolean(target, settings, 'horizontal', defaults);

  // undocumented settings, for tests only
  assignBoolean(target, settings, 'clipAfterFetchOnly', defaults);
  assignBoolean(target, settings, 'clipAfterScrollOnly', defaults);
};
{'fraction_non_alphanumeric': 0.1427601809954751, 'fraction_numerical': 0.0011312217194570137, 'mean_word_length': 4.478314745972739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5379871', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1270, 'n_words': 367}