mirror of
https://github.com/HirziDevs/PteroStats
synced 2026-01-06 21:47:36 +00:00
15 lines
604 B
JavaScript
15 lines
604 B
JavaScript
const prettyBytes = require('prettier-bytes');
|
|
|
|
module.exports = function convertUnits(value, max, unit) {
|
|
unit = unit.toUpperCase();
|
|
switch (unit) {
|
|
case 'PERCENTAGE':
|
|
case 'PERCENT':
|
|
const percentage = Math.floor((value / max) * 100);
|
|
return `${!percentage ? 0 : percentage}%`;
|
|
case 'BYTE':
|
|
return `${prettyBytes(value * 1000000)} / ${max === 0 ? "Unlimited" : prettyBytes(max * 1000000)}`;
|
|
default:
|
|
return `${value.toLocaleString()} ${unit}/${max === 0 ? "Unlimited" : `${max.toLocaleString()} ${unit}`}`;
|
|
}
|
|
} |