Workspace-shared formatting helpers for numeric / size values.
Summary
Functions
Formats a byte count as a human-readable size string.
The heroicon name for a stored file, by its Storage file_type (and PDF
by MIME type) — what every module's file list shows beside a name.
Functions
Formats a byte count as a human-readable size string.
Accepts an integer, Decimal, or nil. Returns the :unknown option
string for nil (or any unrecognised input) and rounds to :decimals
decimal places for the chosen unit. The unit auto-scales to B / KB /
MB / GB based on the size.
Options
:decimals— decimal places for KB/MB/GB output. Default1.:unknown— string returned fornilor unrecognised inputs. Default"Unknown". Pass"0 B"to mimic the file-picker shape.:base—1024(binary, default) or1000(decimal/SI). Some media-browser surfaces use the decimal convention to match what operating systems show; everything else defaults to the binary convention common in dev tooling.
Examples
iex> PhoenixKit.Utils.Format.bytes(0)
"0 B"
iex> PhoenixKit.Utils.Format.bytes(1500)
"1.5 KB"
iex> PhoenixKit.Utils.Format.bytes(1_500_000, decimals: 2)
"1.43 MB"
iex> PhoenixKit.Utils.Format.bytes(1_500_000, base: 1000, decimals: 2)
"1.5 MB"
iex> PhoenixKit.Utils.Format.bytes(nil, unknown: "0 B")
"0 B"
The heroicon name for a stored file, by its Storage file_type (and PDF
by MIME type) — what every module's file list shows beside a name.
iex> PhoenixKit.Utils.Format.file_icon(%{file_type: "image"})
"hero-photo"
iex> PhoenixKit.Utils.Format.file_icon(%{file_type: "document", mime_type: "application/pdf"})
"hero-document-text"
iex> PhoenixKit.Utils.Format.file_icon(nil)
"hero-document"