filesize
Human-readable file size formatting library. Converts byte counts to human-readable strings: filesize(1000000) → '976.56 KiB' or '1 MB' depending on rounding options. Supports decimal (SI/kB) and binary (IEC/KiB) units, configurable precision, locale-aware number formatting, partial results for custom formatting, and exponent control. Used in file upload progress, storage statistics display, bandwidth monitoring, and any UI showing data sizes.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Pure formatting utility — zero security surface.
⚡ Reliability
Best When
You need to display byte counts in a human-friendly format in any JavaScript UI or logging output.
Avoid When
You need to parse human-readable sizes back to bytes (use bytes package), or need locale-specific formatting (filesize has some locale support).
Use Cases
- • Format file sizes for upload progress indicators: '2.5 MB of 10 MB uploaded'
- • Display storage usage in dashboards: filesize(usedBytes) + ' used of ' + filesize(totalBytes)
- • Format API response sizes in developer tools and monitoring dashboards
- • Show download sizes in file browsers or media libraries
- • Format bandwidth statistics in network monitoring UIs
Not For
- • Parsing human-readable sizes back to bytes — filesize formats only; use bytes or a custom parser for reverse conversion
- • Storage arithmetic — convert to bytes first for calculations, then format with filesize
- • Precise scientific display — filesize is for user-friendly display, not precise scientific notation
Interface
Authentication
No authentication — formatting utility library.
Pricing
Fully free, BSD licensed.
Agent Metadata
Known Gotchas
- ⚠ Default uses binary IEC units (KiB, MiB) not SI decimal (kB, MB) — users expecting SI kB/MB must use standard: 'si' option: filesize(bytes, { standard: 'si' })
- ⚠ filesize v10 is ESM-only — use filesize v9 for CommonJS compatibility, or pretty-bytes (also ESM-only) as alternative
- ⚠ Output is a string — cannot do arithmetic on result; convert to bytes first for calculations: const totalBytes = usedBytes + freeBytes; then format separately
- ⚠ Precision vs round options: precision controls significant figures, round controls decimal places — choose based on desired output format
- ⚠ Large numbers (>10^18): exabytes and petabytes are supported but verify your BigInt handling if passing JavaScript Number limits
- ⚠ Locale formatting: locale: true uses Intl.NumberFormat for locale-aware thousands separators — requires Intl support in target environment
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for filesize.
Scores are editorial opinions as of 2026-03-06.