/
gamma
/
Gamma-Editor
Обзор
Документация
Войти
/
gamma
/
Gamma-Editor
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
src/utils/FormatHelper.ts
15 строк
400 B
Vlavimir Solodovnikov
Features
30 май 2022, 01:36
30 май 2022, 01:36
20a0ab8
Код
Авторство
О чём код?
export default class FormatHelper { private constructor() {} public static formatFileSize(size: number): string { const units = ['B', 'KB', 'MB', 'GB']; let currentUnitIndex = 0; while (size >= 1000 && currentUnitIndex < units.length - 1) { size /= 1024; currentUnitIndex++; } return `${size.toFixed(currentUnitIndex ? 2 : 0)} ${units[currentUnitIndex]}`; } }