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

Function formatListWithAnd

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected