6 lines
245 B
TypeScript
6 lines
245 B
TypeScript
|
export default function dataConversion(bytes: number) {
|
||
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||
|
return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`;
|
||
|
}
|