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
parent 8c4a7cb2be
commit 1364ba5784
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 });
}