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

14 lines
480 B
TypeScript
Raw Normal View History

2019-07-28 05:23:51 +02:00
export function bytesToHuman (bytes: number): string {
if (bytes === 0) {
return '0 kB';
}
2019-07-28 05:23:51 +02:00
const i = Math.floor(Math.log(bytes) / Math.log(1000));
// @ts-ignore
2020-03-29 23:19:17 +02:00
return `${(bytes / Math.pow(1000, i)).toFixed(2) * 1} ${[ 'Bytes', 'kB', 'MB', 'GB', 'TB' ][i]}`;
2019-07-28 05:23:51 +02:00
}
export const bytesToMegabytes = (bytes: number) => Math.floor(bytes / 1000 / 1000);
export const randomInt = (low: number, high: number) => Math.floor(Math.random() * (high - low) + low);