<commit_before>import {format as d3Format} from 'd3'

/*
Returns an object with a general formatter function and an
axis formatter function:
{
  axisFormat: function
  format: function,
}
*/
export function unitFormatter(unit = '') {
  let format = function (val) {
    return parseFloat(val).toLocaleString()
  }
  let axisFormat = format
  switch (unit) {
    case 'prosent': {
      const _format = d3Format('.2f')
      format = function (val) {
        return `${_format(val)} %`
      }
      const _axisFormat = d3Format('f')
      axisFormat = function (val) {
        return `${_axisFormat(val)} %`
      }
      break
    }
    case 'promille': {
      const _format = d3Format('.2f')
      format = function (val) {
        return `${_format(val)} ‰`
      }
      axisFormat = format
      break
    }
    case 'kroner': {
      format = function (val) {
        return `${val.toLocaleString()} kr`
      }
      axisFormat = format
      break
    }
    default: {
      break
    }
  }

  return {axisFormat, format}<commit_msg>Update unitFormatter to pass new tests<commit_after>import {format as d3Format} from 'd3'

/*
Returns an object with a general formatter function and an
axis formatter function:
{
  axisFormat: function
  format: function,
}
*/
export function unitFormatter(unit = '') {
  let format = function (val) {
    return parseFloat(val).toLocaleString()
  }
  let axisFormat = format
  switch (unit) {
    case 'prosent': {
      const _format = d3Format('.1f')
      format = function (val) {
        return `${_format(val)} %`
      }
      const _axisFormat = d3Format('f')
      axisFormat = function (val) {
        return `${_axisFormat(val)} %`
      }
      break
    }
    case 'promille': {
      const _format = d3Format('.1f')
      format = function (val) {
        return `${_format(val)} ‰`
      }
      axisFormat = format
      break
    }
    case 'kroner': {
      const _format = d3Format('.1f')
      const billion = 1000000000.0
      const million = 1000000.0
      format = function (val) {
        if (val > billion) {
          return `${_format(val / billion)} mrd kr`
        } else if (val > million) {
          return `${_format(val / million)} mill kr`
        }
        return `${val.toLocaleString()} kr`
      }
      axisFormat = format
      break
    }
    default: {
      break
    }
  }

  return {axisFormat, format}
{'fraction_non_alphanumeric': 0.12364243943191311, 'fraction_numerical': 0.014619883040935672, 'mean_word_length': 2.2018716577540105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '470713', 'n_tokens_mistral': 751, 'n_tokens_neox': 743, 'n_words': 202}