MCPcopy
hub / github.com/CopilotKit/CopilotKit / normalizeUrl

Function normalizeUrl

showcase/shell-docs/src/lib/analytics-utils.ts:15–34  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

13 * - /reference -> /reference (not an integration, unchanged)
14 */
15export function normalizeUrl(url: string): string {
16 if (!url) return url;
17
18 const segments = url.split("/").filter(Boolean);
19
20 if (segments[0] === "integrations" && segments.length > 1) {
21 const integrationId = segments[1];
22 const knownSlugs = new Set(getIntegrations().map((i) => i.slug));
23
24 if (knownSlugs.has(integrationId)) {
25 const restOfPath = segments.slice(2).join("/");
26 const normalized = `/${integrationId}${
27 restOfPath ? "/" + restOfPath : ""
28 }`;
29 return normalized === "/" ? "/" : normalized.replace(/\/$/, "");
30 }
31 }
32
33 return url === "/" ? "/" : url.replace(/\/$/, "");
34}
35
36/**
37 * Normalizes pathnames for analytics tracking.

Callers 1

Calls 4

getIntegrationsFunction · 0.90
filterMethod · 0.80
joinMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…