<commit_before>'use strict';

export default {
  randomId(length) {
    return Math.random().toString(36).substr(2, length);
  }
};<commit_msg>Add "utils.formatNumber" method<commit_after>'use strict';

export function randomId(length) {
  return Math.random().toString(36).substr(2, length);
}



function limitDecimals( num, decCount ) {
  const countMatch = /^([<>])?(\d+)/.exec(decCount);
  let parts = `${num}`.split('.');
  let decLen = parts[1] ? parts[1].length : 0;

  decCount = countMatch ? +countMatch[2] : 0;

  // minimum number of decimals
  if( countMatch[1] === '>' && decLen > decCount ) {
    decCount = decLen;
  }

  // maximum number of decimals
  if( countMatch[1] === '<' ) {
    if(decLen < decCount) {
      decCount = decLen;
    } else {
      num = +num.toFixed(decCount);
      parts =`${num}`.split('.');
      decLen = parts[1] ? parts[1].length : 0;

      decCount = decLen < decCount ? decLen : decCount;
    }
  }

  return num.toFixed(decCount);
}

export function formatNumber(num, decCount=2, sep='.', dec=',') {
  if( isNaN(num) ) { num = 0; }

  // Format the number to the desired number of decimals and split.
  const parts = `${limitDecimals(num, decCount)}`.split('.');

  // insert separator
  parts[0] = parts[0].replace(/(\d)(?=(\d{3})+$)/g, `$1${sep}`);

  // join with decimal delimiter
  return parts.join(dec);
}

{'fraction_non_alphanumeric': 0.19267399267399268, 'fraction_numerical': 0.01611721611721612, 'mean_word_length': 3.392282958199357, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '187910', 'n_tokens_mistral': 496, 'n_tokens_neox': 477, 'n_words': 109}