Bloccs.Web.Format (bloccs_web v0.1.0)

Copy Markdown View Source

Small, dependency-free formatting helpers for the dashboard: human durations, counts, rates, and percentages. Pure functions, easy to unit-test.

Summary

Functions

Compact integer count (1.2k, 3.4M).

Render a millisecond duration coarsely (largest unit only).

A latency in ms rendered with a unit (sub-ms shown in µs).

A 0.0–1.0 fraction as an integer percentage.

A per-second rate, one decimal place.

Render an uptime from a monotonic started_at (ms) relative to now (ms, defaults to the current monotonic clock). Coarse on purpose — "3d", "4h", "12m", "5s", or "just now".

Functions

count(n)

@spec count(integer() | nil) :: String.t()

Compact integer count (1.2k, 3.4M).

duration(ms)

@spec duration(integer()) :: String.t()

Render a millisecond duration coarsely (largest unit only).

latency(ms)

@spec latency(number() | nil) :: String.t()

A latency in ms rendered with a unit (sub-ms shown in µs).

percent(frac)

@spec percent(number() | nil) :: String.t()

A 0.0–1.0 fraction as an integer percentage.

rate(per_sec)

@spec rate(number() | nil) :: String.t()

A per-second rate, one decimal place.

uptime(started_at, now \\ System.monotonic_time(:millisecond))

@spec uptime(integer(), integer()) :: String.t()

Render an uptime from a monotonic started_at (ms) relative to now (ms, defaults to the current monotonic clock). Coarse on purpose — "3d", "4h", "12m", "5s", or "just now".