<commit_before>import numeral from 'numeral';
import { isNil } from 'ramda';

interface FormatMetricValueProps {
  value: number | null;
  unit: string;
  base?: number;
}

const formatMetricValue = ({
  value,
  unit,
  base = 1000,
}: FormatMetricValueProps): string | null => {
  if (isNil(value)) {
    return null;
  }

  const base2Units = [
    'B',
    'bytes',
    'bytespersecond',
    'B/s',
    'B/sec',
    'o',
    'octets',
  ];

  const base1024 = base2Units.includes(unit) || Number(base) === 1024;

  const formatSuffix = base1024 ? ' ib' : 'a';

  return numeral(value)
    .format(`0.[00]${formatSuffix}`)
    .replace(/\s|i|B/g, '');
};

export default formatMetricValue;<commit_msg>fix(ui): Adapt graph scale for b/s unit (#9579)<commit_after>import numeral from 'numeral';
import { isNil } from 'ramda';

interface FormatMetricValueProps {
  value: number | null;
  unit: string;
  base?: number;
}

const formatMetricValue = ({
  value,
  unit,
  base = 1000,
}: FormatMetricValueProps): string | null => {
  if (isNil(value)) {
    return null;
  }

  const base2Units = [
    'B',
    'bytes',
    'bytespersecond',
    'B/s',
    'B/sec',
    'o',
    'octets',
    'b/s',
    'b',
  ];

  const base1024 = base2Units.includes(unit) || Number(base) === 1024;

  const formatSuffix = base1024 ? ' ib' : 'a';

  return numeral(value)
    .format(`0.[00]${formatSuffix}`)
    .replace(/\s|i|B/g, '');
};

export default formatMetricValue;
{'fraction_non_alphanumeric': 0.17099863201094392, 'fraction_numerical': 0.03146374829001368, 'mean_word_length': 3.2283236994219653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1119632', 'n_tokens_mistral': 570, 'n_tokens_neox': 529, 'n_words': 120}