formatSize
Format a byte count into a human-readable string with the appropriate unit.
Each unit is 1024 of the previous (binary prefix). The result is formatted
with one decimal place, unless integerBelowFirstUnit is set.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
bytes | number | A non-negative integer representing a byte count. |
options | FormatSizeOptions | Options. |
Returns
Section titled “Returns”string — A human-readable string such as '0.0B', '1.5KB', '3.2MB'.
Examples
Section titled “Examples”Format bytes to human-readable size
Section titled “Format bytes to human-readable size”Converts a raw byte count to a human-readable string using binary prefixes.
Space before the unit, and a bare integer below the first unit
Section titled “Space before the unit, and a bare integer below the first unit”unitSeparator inserts a separator before the unit; integerBelowFirstUnit drops the decimal for byte counts under 1024.
Related Types
Section titled “Related Types”FormatSizeOptions
Section titled “FormatSizeOptions”Options for formatSize.
