1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-24 01:52:30 +01:00
Pterodactyl-Panel/resources/scripts/helpers.ts

11 lines
289 B
TypeScript

export function bytesToHuman (bytes: number): string {
if (bytes === 0) {
return '0 kB';
}
const i = Math.floor(Math.log(bytes) / Math.log(1000));
// @ts-ignore
return `${(bytes / Math.pow(1000, i)).toFixed(2) * 1} ${['Bytes', 'kB', 'MB', 'GB', 'TB'][i]}`;
}