Files
SpotMicroESP32-Leika/app/src/lib/utilities/string-utilities.ts
T
Rune Harlyk 22b54261f0 📏 Formats app code
2024-02-23 09:16:20 +01:00

6 lines
246 B
TypeScript

export const humanFileSize = (size: number): string => {
const units = ['B', 'kB', 'MB', 'GB', 'TB'];
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return Number((size / Math.pow(1024, i)).toFixed(2)) * 1 + units[i];
};