2020-06-10 14:00:43 -06:00
|
|
|
export const bytesToMegabytes = (bytes: number) => Math.floor(bytes / 1024 / 1024);
|
|
|
|
|
|
|
|
export const megabytesToBytes = (mb: number) => Math.floor(mb * 1024 * 1024);
|
|
|
|
|
2019-07-27 20:23:51 -07:00
|
|
|
export function bytesToHuman (bytes: number): string {
|
2019-08-17 16:03:10 -07:00
|
|
|
if (bytes === 0) {
|
|
|
|
return '0 kB';
|
|
|
|
}
|
|
|
|
|
2020-06-10 14:00:43 -06:00
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
|
|
return `${Number((bytes / Math.pow(1024, i)).toFixed(2))} ${[ 'Bytes', 'kB', 'MB', 'GB', 'TB' ][i]}`;
|
2019-07-27 20:23:51 -07:00
|
|
|
}
|
2019-09-29 13:23:15 -07:00
|
|
|
|
2020-06-10 14:00:43 -06:00
|
|
|
export function megabytesToHuman (mb: number): string {
|
|
|
|
return bytesToHuman(megabytesToBytes(mb));
|
|
|
|
}
|
2020-04-10 12:41:08 -07:00
|
|
|
|
|
|
|
export const randomInt = (low: number, high: number) => Math.floor(Math.random() * (high - low) + low);
|
2020-04-10 13:57:24 -07:00
|
|
|
|
|
|
|
export const cleanDirectoryPath = (path: string) => path.replace(/(^#\/*)|(\/(\/*))|(^$)/g, '/');
|
2020-07-04 21:46:49 -07:00
|
|
|
|
|
|
|
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|