Hooks
Functions
fileSizeUnit
fileSizeUnit function formats a file size (in bytes) into a human-readable string with appropriate units (kB, MB, etc.).
Example
import fileSizeUnit from '@/utils/fileSizeUnit'
// Using SI units (default)
const sizeSI = fileSizeUnit(1500) // output: '1.5 kB'
// Using binary units
const sizeBinary = fileSizeUnit(1500, false) // output: '1.46 KiB'
// Specifying decimal places
const sizeWithDecimal = fileSizeUnit(1536000, true, 2) // output: '1.54 MB'
Params
| param | Description | Type | Default |
|---|---|---|---|
| bytes | The file size in bytes. | number | - |
| si | Determines whether to use SI units (base 1000) or binary units (base 1024). | boolean | - |
| dp | The number of decimal places to include in the formatted output. | number | - |
Params
| return | Description | Type | Default |
|---|---|---|---|
| result | The formatted file size with the appropriate unit, based on the number of bytes. | string | - |