Code Explainers
Code explainers tagged #logarithms
typescript
export interface FormatBytesOptions { decimals?: number; binary?: boolean; }
Formatting byte counts into human-readable sizes
formatting
logarithms
default-parameters
Intermediate
8 steps
javascript
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']; export function formatBytes(bytes, { decimals = 1, binary = false } = {}) { if (!Number.isFinite(bytes)) {
Formatting byte counts into human units
logarithms
formatting
default-parameters
Intermediate
8 steps