- Recover the IndexedDB and in-memory document cache behind the storage domain - Add persistent outbox supersession, cache eviction, import validation, and naming helpers - Keep the substrate provider-neutral and cover its pure behavior Co-authored-by: Rob Coenen <753704+rcoenen@users.noreply.github.com>
15 lines
526 B
TypeScript
15 lines
526 B
TypeScript
/** Human-readable byte size (e.g. 1.2 MB). */
|
|
export function formatStorageBytes(bytes: number): string {
|
|
if (!Number.isFinite(bytes) || bytes < 0) return '0 B'
|
|
if (bytes < 1024) return `${Math.round(bytes)} B`
|
|
const units = ['KB', 'MB', 'GB', 'TB'] as const
|
|
let value = bytes / 1024
|
|
let unitIndex = 0
|
|
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
value /= 1024
|
|
unitIndex += 1
|
|
}
|
|
const digits = value >= 10 || unitIndex === 0 ? 0 : 1
|
|
return `${value.toFixed(digits)} ${units[unitIndex]}`
|
|
}
|