mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 12:20:20 +01:00
Adjust file size display
This commit is contained in:
parent
5a2d81c5bd
commit
ceadcd464e
|
|
@ -14,6 +14,7 @@ describe("gets formatted size", () => {
|
||||||
[1048081, "0.99 MB"],
|
[1048081, "0.99 MB"],
|
||||||
[9968640, "9.50 MB"],
|
[9968640, "9.50 MB"],
|
||||||
[16777216, "16.0 MB"],
|
[16777216, "16.0 MB"],
|
||||||
|
[45266957, "43.1 MB"],
|
||||||
];
|
];
|
||||||
|
|
||||||
test.each(formattedSizeCases)("given %p render %p", (size, result) =>
|
test.each(formattedSizeCases)("given %p render %p", (size, result) =>
|
||||||
|
|
|
||||||
|
|
@ -493,12 +493,22 @@ const bytesInMB = 1022976; // 1024 * 999
|
||||||
const bytesInGB = 1047527424; // 1024 * 1024 * 999
|
const bytesInGB = 1047527424; // 1024 * 1024 * 999
|
||||||
const bytesInTB = 1072668082176; // 1024 * 1024 * 1024 * 999
|
const bytesInTB = 1072668082176; // 1024 * 1024 * 1024 * 999
|
||||||
|
|
||||||
const formatNumber = (number: number): string =>
|
const formatNumber = (number: number): string => {
|
||||||
new Intl.NumberFormat("en-US", {
|
const formattedNumber = new Intl.NumberFormat("en-US", {
|
||||||
maximumSignificantDigits: number < 1 ? 2 : 3,
|
maximumSignificantDigits: number < 1 ? 2 : 4,
|
||||||
minimumSignificantDigits: number < 1 ? 2 : 3,
|
minimumSignificantDigits: number < 1 ? 2 : 3,
|
||||||
}).format(Number(number.toFixed(4).slice(0, -2)));
|
}).format(Number(number.toFixed(4).slice(0, -2)));
|
||||||
|
|
||||||
|
const [integer, decimal] = formattedNumber.split(".");
|
||||||
|
|
||||||
|
if (integer.length === 3) return integer;
|
||||||
|
if (integer.length === 2 && decimal.length === 2) {
|
||||||
|
return `${integer}.${decimal[0]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedNumber;
|
||||||
|
};
|
||||||
|
|
||||||
export const getFormattedSize = (size = 0): string => {
|
export const getFormattedSize = (size = 0): string => {
|
||||||
if (size === 1) return "1 byte";
|
if (size === 1) return "1 byte";
|
||||||
if (size < bytesInKB) return `${size} bytes`;
|
if (size < bytesInKB) return `${size} bytes`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user