refactor: share human list formatting

This commit is contained in:
Peter Steinberger
2026-04-20 13:54:24 +01:00
parent c6a0452d13
commit a1bd02fdfd
3 changed files with 14 additions and 26 deletions

12
src/shared/human-list.ts Normal file
View File

@@ -0,0 +1,12 @@
export function formatHumanList(values: readonly string[]): string {
if (values.length === 0) {
return "";
}
if (values.length === 1) {
return values[0];
}
if (values.length === 2) {
return `${values[0]} or ${values[1]}`;
}
return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`;
}