Format
Formatting helpers for lit-material apps: bytes, compact numbers, durations, CPU, and Kubernetes quantities ("512Mi", "500m"). Locale-aware, no dependencies.
- 929 B gzipped
- @lit-material/format 0.1.0
- Renders on the server
Example
Format
Locale-aware helpers for sizes, counts, durations and Kubernetes quantities — plain functions, no element.
formatBytes(1536) | 1.5 KiB |
formatBytes(1500, { binary: false }) | 1.5 kB |
formatBytes(parseQuantity("512Mi")) | 512 MiB |
formatNumber(12345, { compact: true }) | 12.3K |
formatDuration(7_500_000) | 2 hr, 5 min |
formatDuration(65_000, { unitDisplay: "narrow" }) | 1m 5s |
formatCpu("250m") | 0.25 cores |
Install
npm install @lit-material/format @lit-material/tokens
import "@lit-material/format";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide