ui/ui_format.ts

Formatting utilities for UI display.

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

Declarations
#

7 declarations

view source

format_audit_metadata
#

ui/ui_format.ts view source

(event_type: "login" | "logout" | "bootstrap" | "signup" | "password_change" | "session_revoke" | "session_revoke_all" | "token_create" | "token_revoke" | "token_revoke_all" | "permit_grant" | "permit_revoke" | "invite_create" | "invite_delete" | "app_settings_update", metadata: Record<...> | null): string

Format audit event metadata for display based on event type.

event_type

the audit event type

type "login" | "logout" | "bootstrap" | "signup" | "password_change" | "session_revoke" | "session_revoke_all" | "token_create" | "token_revoke" | "token_revoke_all" | "permit_grant" | "permit_revoke" | "invite_create" | "invite_delete" | "app_settings_update"

metadata

the metadata object (may be null)

type Record<string, unknown> | null

returns

string

human-readable summary string

format_datetime_local
#

ui/ui_format.ts view source

(timestamp: string | number | Date): string

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

timestamp

a date value

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

Format a timestamp as a relative time string.

timestamp

a date value (string, number, or Date)

type string | number | Date

now

reference time in ms since epoch, defaults to Date.now()

type number
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

Format milliseconds as a human-friendly uptime string.

ms

duration in milliseconds

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

Format an arbitrary value for table cell display.

value

the value to format

type unknown

returns

string

string representation suitable for UI display

truncate_middle
#

ui/ui_format.ts view source

(str: string, max_length: number, separator?: string): string

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

str

the string to truncate

type string

max_length

maximum total length including separator

type number

separator

the middle separator

type string
default '…'

returns

string

the truncated string, or the original if it fits

truncate_uuid
#

ui/ui_format.ts view source

(uuid: string): string

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

uuid

the UUID string to truncate

type string

returns

string

a 12-character truncated UUID like a1b2c…7890

Imported by
#