All files / src/shared/lib/helpers formatBytes.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 144x 168x 79x     89x 76x 76x     13x 13x    
export const bytesToHumanReadable = (bytes: number) => {
  if (bytes < 1024) {
    return `${bytes} bytes`;
  }
 
  if (bytes < 1024 * 1024) {
    const kb = bytes / 1024;
    return `${parseFloat(kb.toFixed(2))} KiB`;
  }
 
  const mb = bytes / (1024 * 1024);
  return `${parseFloat(mb.toFixed(2))} MiB`;
};