<commit_before>/* eslint-disable import/prefer-default-export */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import { truncateString } from 'sussol-utilities';
import { generalStrings, modalStrings } from '../localization';

export const formatErrorItemNames = items => {
  const MAX_ITEMS_IN_ERROR_MESSAGE = 4; // Number of items to display in finalise error modal.
  const MAX_ITEM_STRING_LENGTH = 40; // Length of string representing item in error modal.
  let itemsString = '';
  items.forEach((item, index) => {
    if (!item) return; // Rerendering sometimes causes a crash here.
    if (index >= MAX_ITEMS_IN_ERROR_MESSAGE) return;
    itemsString += truncateString(`\n${item.itemCode} - ${item.itemName}`, MAX_ITEM_STRING_LENGTH);
  });
  if (items.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
    itemsString +=
      `\n${modalStrings.and} ` +
      `${items.length - MAX_ITEMS_IN_ERROR_MESSAGE} ` +
      `${modalStrings.more}.`;
  }
  return itemsString;
};

/**
 * Rounds a number to the provided number of digits. I.e.
 * roundNumber(17.123, 2) = 17.12
 *
 * @param {Number} number           The number to round.
 * @param {Number} fractionalDigits The number of digits to round to.
 */
export const roundNumber = (number, fractionalDigits) =>
  Number(parseFloat(number).toFixed(fractionalDigits));

export const formatTemperature = temperature => {
  const validTemperature = temperature != null;
  const degree = String.fromCharCode(176);

  return validTemperature ? `${temperature}${degree}C` : generalStrings.not_available;
};

export const formatTemperatureExposure = ({
  minimumTemperature = Infinity,
  maximumTemperature = -Infinity,
} = {}) => {
  console.log(minimumTemperature, maximumTemperature);
  const infinityTemperatures = minimumTemperature === Infinity || maximumTemperature === -Infinity;
  if (infinityTemperatures) return 'No temperatures recorded';

  return `${formatTemperature(minimumTemperature)} - ${formatTemperature(maximumTemperature)}`;
};

export const formatTimeDifference = duration => {
  const suffixes = [generalStrings.days, generalStrings.hours, generalStrings.minutes];
  const durations = [duration.days(), duration.hours(), duration.minutes()];<commit_msg>Add remove log<commit_after>/* eslint-disable import/prefer-default-export */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import { truncateString } from 'sussol-utilities';
import { generalStrings, modalStrings } from '../localization';

export const formatErrorItemNames = items => {
  const MAX_ITEMS_IN_ERROR_MESSAGE = 4; // Number of items to display in finalise error modal.
  const MAX_ITEM_STRING_LENGTH = 40; // Length of string representing item in error modal.
  let itemsString = '';
  items.forEach((item, index) => {
    if (!item) return; // Rerendering sometimes causes a crash here.
    if (index >= MAX_ITEMS_IN_ERROR_MESSAGE) return;
    itemsString += truncateString(`\n${item.itemCode} - ${item.itemName}`, MAX_ITEM_STRING_LENGTH);
  });
  if (items.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
    itemsString +=
      `\n${modalStrings.and} ` +
      `${items.length - MAX_ITEMS_IN_ERROR_MESSAGE} ` +
      `${modalStrings.more}.`;
  }
  return itemsString;
};

/**
 * Rounds a number to the provided number of digits. I.e.
 * roundNumber(17.123, 2) = 17.12
 *
 * @param {Number} number           The number to round.
 * @param {Number} fractionalDigits The number of digits to round to.
 */
export const roundNumber = (number, fractionalDigits) =>
  Number(parseFloat(number).toFixed(fractionalDigits));

export const formatTemperature = temperature => {
  const validTemperature = temperature != null;
  const degree = String.fromCharCode(176);

  return validTemperature ? `${temperature}${degree}C` : generalStrings.not_available;
};

export const formatTemperatureExposure = ({
  minimumTemperature = Infinity,
  maximumTemperature = -Infinity,
} = {}) => {
  const infinityTemperatures = minimumTemperature === Infinity || maximumTemperature === -Infinity;
  if (infinityTemperatures) return 'No temperatures recorded';

  return `${formatTemperature(minimumTemperature)} - ${formatTemperature(maximumTemperature)}`;
};

export const formatTimeDifference = duration => {
  const suffixes = [generalStrings.days, generalStrings.hours, generalStrings.minutes];
  const durations = [duration.days(), duration.hours(), duration.minutes()];
{'fraction_non_alphanumeric': 0.12528318985047576, 'fraction_numerical': 0.009062075215224286, 'mean_word_length': 4.5886075949367084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1179450', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1274, 'n_words': 331}