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