docling-studio/frontend/src/shared/format.js
2026-03-20 12:36:26 +01:00

10 lines
299 B
JavaScript

/**
* Format a byte count as a human-readable size string.
* @param {number|null|undefined} bytes
* @returns {string}
*/
export function formatSize(bytes) {
if (!bytes) return ''
const mb = bytes / (1024 * 1024)
return mb >= 1 ? `${mb.toFixed(1)} MB` : `${(bytes / 1024).toFixed(0)} KB`
}