MCPcopy
hub / github.com/directus/directus / replaceVersion

Function replaceVersion

app/src/modules/visual/utils/version-url.ts:60–95  ·  view source on GitHub ↗
(url: string, placement: VersionPlacement, newVersion: string)

Source from the content-addressed store, hash-verified

58}
59
60export function replaceVersion(url: string, placement: VersionPlacement, newVersion: string) {
61 if (!placement) return url;
62
63 const parsed = parseUrl(url);
64 if (!parsed) return url;
65
66 if (placement.type === 'query') {
67 parsed.searchParams.set(placement.paramName, newVersion);
68 return parsed.href;
69 }
70
71 if (placement.type === 'path') {
72 const segments = parsed.pathname.split('/');
73 segments[placement.segmentIndex] = newVersion;
74 parsed.pathname = segments.join('/');
75 return parsed.href;
76 }
77
78 if (placement.type === 'subdomain') {
79 const labels = parsed.hostname.split('.');
80 labels[placement.labelIndex] = newVersion;
81 parsed.hostname = labels.join('.');
82 return parsed.href;
83 }
84
85 if (placement.type === 'hash') {
86 const prefix = parsed.hash.startsWith('#/') ? '#/' : '#';
87 const hashContent = parsed.hash.replace(/^#\/?/, '');
88 const segments = hashContent.split('/');
89 segments[placement.segmentIndex] = newVersion;
90 parsed.hash = prefix + segments.join('/');
91 return parsed.href;
92 }
93
94 return url;
95}
96
97export function matchesTemplate(templateUrl: string, concreteUrl: string, placement: VersionPlacement) {
98 if (!placement) return sameOrigin(templateUrl, concreteUrl);

Callers 2

Calls 3

parseUrlFunction · 0.90
joinMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected