MCPcopy
hub / github.com/anomalyco/models.dev / compactMetadataDescription

Function compactMetadataDescription

packages/web/src/render.tsx:572–589  ·  view source on GitHub ↗
(parts: Array<string | undefined>, maxLength: number)

Source from the content-addressed store, hash-verified

570}
571
572function compactMetadataDescription(parts: Array<string | undefined>, maxLength: number) {
573 const compacted = parts
574 .map((part) => part?.trim())
575 .filter((part): part is string => Boolean(part))
576 .map(ensureSentence)
577 .join(" ");
578
579 if (compacted.length <= maxLength) return compacted;
580
581 const shortened = compacted.slice(0, maxLength - 1);
582 const lastBreak = Math.max(
583 shortened.lastIndexOf("."),
584 shortened.lastIndexOf(";"),
585 shortened.lastIndexOf(","),
586 );
587 const trimmed = (lastBreak > maxLength * 0.6 ? shortened.slice(0, lastBreak) : shortened).trim();
588 return `${trimmed.replace(/[.,;:]$/, "")}.`;
589}
590
591function ensureSentence(value: string) {
592 return /[.!?]$/.test(value) ? value : `${value}.`;

Callers 3

modelPageMetadataFunction · 0.85
providerPageMetadataFunction · 0.85
labPageMetadataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected