MCPcopy Create free account
hub / github.com/freecodexyz/free-code / formatListWithAnd

Function formatListWithAnd

src/components/TrustDialog/utils.ts:79–104  ·  view source on GitHub ↗
(items: string[], limit?: number)

Source from the content-addressed store, hash-verified

77 * @param limit - Optional limit for how many items to show before summarizing (ignored if 0)
78 */
79export function formatListWithAnd(items: string[], limit?: number): string {
80 if (items.length === 0) return ''
81
82 // Ignore limit if it's 0
83 const effectiveLimit = limit === 0 ? undefined : limit
84
85 // If no limit or items are within limit, use normal formatting
86 if (!effectiveLimit || items.length <= effectiveLimit) {
87 if (items.length === 1) return items[0]!
88 if (items.length === 2) return `${items[0]} and ${items[1]}`
89
90 const lastItem = items[items.length - 1]!
91 const allButLast = items.slice(0, -1)
92 return `${allButLast.join(', ')}, and ${lastItem}`
93 }
94
95 // If we have more items than the limit, show first few and count the rest
96 const shown = items.slice(0, effectiveLimit)
97 const remaining = items.length - effectiveLimit
98
99 if (shown.length === 1) {
100 return `${shown[0]} and ${remaining} more`
101 }
102
103 return `${shown.join(', ')}, and ${remaining} more`
104}
105
106/**
107 * Check if settings have otelHeadersHelper configured

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected