refactor: share sampled entry summary formatting

This commit is contained in:
Peter Steinberger
2026-03-08 00:03:02 +00:00
parent cc03c097c5
commit 990fc36cbd
5 changed files with 77 additions and 28 deletions

View File

@@ -0,0 +1,14 @@
export function summarizeStringEntries(params: {
entries?: ReadonlyArray<string> | null;
limit?: number;
emptyText?: string;
}): string {
const entries = params.entries ?? [];
if (entries.length === 0) {
return params.emptyText ?? "";
}
const limit = Math.max(1, Math.floor(params.limit ?? 6));
const sample = entries.slice(0, limit);
const suffix = entries.length > sample.length ? ` (+${entries.length - sample.length})` : "";
return `${sample.join(", ")}${suffix}`;
}