1.1.2Updated a month ago
const SCALE = ['B', 'KiB', 'MiB', 'GiB', 'TB', 'PB', 'EB', 'YB', 'ZB'];

export const FileSize = (bytes: number) => {
  let scale_index = 0;
  while(bytes >= 1024) {
    bytes /= 1024;
    scale_index++;
  }

  return `${bytes.toFixed(2)}${SCALE[scale_index]}`;
}