跳到主要内容

std/label

std/label

导入自 @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).

参数

名称类型说明
row{ readonly [field: string]: unknown; }
pathsreadonly string[]
show?(path: string, value: unknown) => string

示例

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

源码: packages/std/src/label.ts:48