Skip to content

Commit

Permalink
Change getHumanReadableMemory to IEC unit
Browse files Browse the repository at this point in the history
  • Loading branch information
marians committed Aug 15, 2024
1 parent 69c27ff commit 2bc78e4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,22 @@ export type DeepPartial<T> = T extends object
: T;

/**
* Format memory size in GB to human readable format, to 1 decimal place if the value is between 1TB and 10TB. If mininum decimals is set,
* Format memory size in Bytes to human readable format, to 1 decimal place if the value is between 1TiB and 10TiB. If mininum decimals is set,
* it will always return a string with at least that many decimals.
*/
export function getHumanReadableMemory(size: number, minDecimals: number = 0) {
const formattedSize = humanFileSize(
// eslint-disable-next-line no-magic-numbers
size * 1000 * 1000 * 1000,
true,
false, // use IEC units
minDecimals + 1
);

const factor =
// eslint-disable-next-line no-magic-numbers
10 **
// eslint-disable-next-line no-magic-numbers
(formattedSize.unit === 'TB' && parseFloat(formattedSize.value) < 10
(formattedSize.unit === 'TiB' && parseFloat(formattedSize.value) < 10
? Math.max(1, minDecimals)
: minDecimals);

Expand Down

0 comments on commit 2bc78e4

Please sign in to comment.