<commit_before>function assertPositive(number, error) {
  if (number < 0) {
    throw new Error(error);
  }
  return number;
}

export function differ(file, commits) {
  return ['initial'].concat(commits).concat('neverShow').reduce((result, commit) => {
    result.push(commit);
    result.push(commit + 'Solved');
    return result;
  }, []).reduce((result, commit, index, arr) => {
    // tslint:disable-next-line:max-line-length TODO: Can this regex be shortened and this comment removed?
    result[commit] = file.replace(/\/\*[\n\s]*d:([a-z]+)(:[a-z]+)?(?:\/(trimBoth|trimLeading|trimTrailing))?[\n\s]*\*\/([\n\s]*)((?:.|\n)*?)([\n\s]*)\/\*\/d\*\//gi,
      function (match, from, to, trim: 'trimBoth'|'trimLeading'|'trimTrailing', spaceLeading, value, spaceTrailing) {
        if (trim === 'trimBoth' || trim === 'trimLeading') {
          spaceLeading = '';
        }
        if (trim === 'trimBoth' || trim === 'trimTrailing') {
          spaceTrailing = '';
        }
        const fromIndex = assertPositive(arr.indexOf(from), `[Differ] Invalid commit: ${from}`);
        const toIndex = to ? assertPositive(arr.indexOf(to.substr(1)), `[Differ] Invalid commit: ${to.substr(1)}`) : arr.length;
        return (index >= fromIndex && index <= toIndex) ? (spaceLeading + value + spaceTrailing) : '';
      });
    return result;
  }, {});
}
<commit_msg>Handle newlines on Windows. (kirjs)<commit_after>function assertPositive(number, error) {
  if (number < 0) {
    throw new Error(error);
  }
  return number;
}

export function differ(file, commits) {
  return ['initial'].concat(commits).concat('neverShow').reduce((result, commit) => {
    result.push(commit);
    result.push(commit + 'Solved');
    return result;
  }, []).reduce((result, commit, index, arr) => {
    // tslint:disable-next-line:max-line-length TODO: Can this regex be shortened and this comment removed?
    result[commit] = file.replace(/\/\*[\r\n\s]*d:([a-z]+)(:[a-z]+)?(?:\/(trimBoth|trimLeading|trimTrailing))?[\r\n\s]*\*\/([\n\s]*)((?:.|\n|\r)*?)([\r\n\s]*)\/\*\/d\*\//gi,
      function (match, from, to, trim: 'trimBoth'|'trimLeading'|'trimTrailing', spaceLeading, value, spaceTrailing) {
        if (trim === 'trimBoth' || trim === 'trimLeading') {
          spaceLeading = '';
        }
        if (trim === 'trimBoth' || trim === 'trimTrailing') {
          spaceTrailing = '';
        }
        const fromIndex = assertPositive(arr.indexOf(from), `[Differ] Invalid commit: ${from}`);
        const toIndex = to ? assertPositive(arr.indexOf(to.substr(1)), `[Differ] Invalid commit: ${to.substr(1)}`) : arr.length;
        return (index >= fromIndex && index <= toIndex) ? (spaceLeading + value + spaceTrailing) : '';
      });
    return result;
  }, {});
}

{'fraction_non_alphanumeric': 0.21535103674063297, 'fraction_numerical': 0.0021826118588577663, 'mean_word_length': 3.378980891719745, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4087384', 'n_tokens_mistral': 936, 'n_tokens_neox': 907, 'n_words': 178}