Skip to content

std/label

std/label

Import from @norbital-ai/std/label

std/label (§3.7): a record's title from its model's label paths. Each path's value is shown per kind (show, the ui's formatter where one is at hand; else a locale-free default for dates, instants, decimals and relations), empty terms are dropped and the rest joined with ' · '. Never a uuid and never a JSON blob: a record that cannot name itself is null, and the caller shows its own placeholder.

label function

function label(row: { readonly [field: string]: unknown; }, paths: readonly string[], show?: (path: string, value: unknown) => string): string | null

A record's title from its model's label paths: each value shown per kind (through show when given), empty terms dropped, the rest joined with ·; null when nothing names the record (never a uuid or JSON).

Parameters

NameTypeDescription
row{ readonly [field: string]: unknown; }
pathsreadonly string[]
show?(path: string, value: unknown) => string

Example

label({ name: 'Ann', team: { name: 'Ops' } }, ['name', 'team.name']) // 'Ann · Ops'

Source: packages/std/src/label.ts:48