ui/ui_format.ts

Formatting utilities for UI display.

Value formatting, relative timestamps, uptime display, absolute timestamp formatting, and audit metadata formatting.

view source

Declarations
#

8 declarations

count_in_window
#

ui/ui_format.ts view source

(rows: readonly { created_at: string; }[], window_start: number, cap: number): { count: number; label: string; } import {count_in_window} from '@fuzdev/fuz_app/ui/ui_format.js';

Count the rows of a newest-first list created at or after window_start, for a list fetched with a row cap. The label reads N+ when the cap may cut the window off — the list is full and its oldest row is still inside the window.

rows

newest-first rows, as a capped list query returns them

type readonly { created_at: string; }[]

window_start

the window's start, in epoch milliseconds

type number

cap

the row limit the list was fetched with

type number

returns

{ count: number; label: string; }

the count and its display label

format_audit_metadata
#

ui/ui_format.ts view source

(event_type: string, metadata: Record<string, unknown> | null): string import {format_audit_metadata} from '@fuzdev/fuz_app/ui/ui_format.js';

Format audit event metadata for display based on event type.

event_type

builtin or consumer-registered audit event type

type string

metadata

type Record<string, unknown> | null

returns

string

format_datetime_local
#

ui/ui_format.ts view source

(timestamp: string | number | Date): string import {format_datetime_local} from '@fuzdev/fuz_app/ui/ui_format.js';

Format a timestamp as an absolute datetime string for title attributes.

timestamp

type string | number | Date

returns

string

readable absolute datetime like "2026-03-21 14:30:00 UTC"

format_relative_time
#

ui/ui_format.ts view source

(timestamp: string | number | Date, now?: number): string import {format_relative_time} from '@fuzdev/fuz_app/ui/ui_format.js';

Format a timestamp as a relative time string.

timestamp

type string | number | Date

now?

type number
optional default Date.now()

returns

string

human-friendly relative time (e.g. "2m ago", "3h ago", "5d ago", "2mo ago", "1y ago")

format_uptime
#

ui/ui_format.ts view source

(ms: number): string import {format_uptime} from '@fuzdev/fuz_app/ui/ui_format.js';

Format milliseconds as a human-friendly uptime string.

ms

type number

returns

string

human-friendly duration (e.g. "45s", "12m", "3h 15m", "2d 5h")

format_value
#

ui/ui_format.ts view source

(value: unknown): string import {format_value} from '@fuzdev/fuz_app/ui/ui_format.js';

Format an arbitrary value for table cell display.

value

type unknown

returns

string

truncate_middle
#

ui/ui_format.ts view source

(str: string, max_length: number, separator?: string): string import {truncate_middle} from '@fuzdev/fuz_app/ui/ui_format.js';

Truncate a string by keeping the start and end, with a separator in the middle.

str

type string

max_length

total length including separator

type number

separator?

type string
optional default '…'

returns

string

the truncated string, or the original if it fits

truncate_uuid
#

ui/ui_format.ts view source

(uuid: string): string import {truncate_uuid} from '@fuzdev/fuz_app/ui/ui_format.js';

Truncate a UUID for display, keeping start and end visible.

uuid

type string

returns

string

a 12-character truncated UUID like a1b2c…7890

Imported by
#