fix: correct unit conversion displaying wrong resource

This commit is contained in:
Hirzi
2024-09-11 09:50:18 +07:00
committed by GitHub
parent 62d66942c1
commit 1f4eeae942

View File

@@ -1,15 +1,15 @@
const prettyBytes = require('prettier-bytes');
module.exports = function convertUnits(value1, value2, unit) {
unit = unit.toUpperCase();
switch (unit) {
case 'PERCENTAGE':
case 'PERCENT':
const percentage = Math.floor((value1 / value2) * 100);
return `${!percentage ? 0 : percentage}%`;
case 'BYTE':
return `${prettyBytes(value1)} / ${prettyBytes(value2)}`;
default:
return `${value1.toLocaleString()} ${unit}/${value2.toLocaleString()} ${unit}`;
}
const prettyBytes = require('prettier-bytes');
module.exports = function convertUnits(value1, value2, unit) {
unit = unit.toUpperCase();
switch (unit) {
case 'PERCENTAGE':
case 'PERCENT':
const percentage = Math.floor((value1 / value2) * 100);
return `${!percentage ? 0 : percentage}%`;
case 'BYTE':
return `${prettyBytes(value1 * 1000000)} / ${value2 === 0 ? "Unlimited" : prettyBytes(value2 * 1000000)}`;
default:
return `${value1.toLocaleString()} ${unit}/${value2 === 0 ? "Unlimited" : `${value2.toLocaleString()} ${unit}`}`;
}
}