export const isInRange = (value: number, min = 0, max = Infinity) => value >= min && value <= max;

export const getNumberInRange = (value: number, min = 0, max = Infinity) => {
  if (value < min) {
    return min;
  }
  if (value > max) {
    return max;
  }

  return value;
};

const siSymbolList = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi'];
export const abbreviateNumber = (number: number, digitsAfterDot = 1, returnSeparately = false) => {
  const float = parseFloat(`${number}`);
  const tier = Math.floor(Math.log10(parseInt(`${Math.abs(float)}`, 10) || 1) / 3);
  const scaled = (float / 1000 ** tier).toFixed(digitsAfterDot).replace(/\.0+$/, '');

  if (returnSeparately) {
    return { result: scaled, tier: siSymbolList[tier] };
  }

  return `${scaled}${siSymbolList[tier]}`;
};

export const isNumber = (value: unknown) => typeof value === 'number' && !Number.isNaN(value);
