Vary number of decimals of file sizes

This commit is contained in:
Fedor Indutny 2025-02-11 15:01:27 -08:00 committed by GitHub
commit 1364ba5784
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -2,6 +2,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
import filesize from 'filesize';
export function formatFileSize(size: number, decimals = 0): string {
return filesize(size, { round: decimals });
// Intentional, `filesize` uses `jedec` standard by default
const MB = 1000 * 1000;
export function formatFileSize(size: number): string {
return filesize(size, { round: size < MB ? 0 : 1 });
}