MCPcopy Index your code
hub / github.com/observablehq/framework / relativePath

Function relativePath

src/path.ts:10–21  ·  view source on GitHub ↗
(source: string, target: string)

Source from the content-addressed store, hash-verified

8 * from the root.
9 */
10export function relativePath(source: string, target: string): string {
11 if (/^\w+:/.test(target)) return target;
12 const from = join("/", source).split(/[/]+/g).slice(0, -1);
13 const to = join("/", target).split(/[/]+/g);
14 const f = to.pop()!;
15 const m = from.length;
16 const n = Math.min(m, to.length);
17 let i = 0;
18 while (i < n && from[i] === to[i]) ++i;
19 const k = m - i;
20 return (k ? "../".repeat(k) : "./") + to.slice(i).concat(f).join("/");
21}
22
23/**
24 * Returns the path to the specified target within the given source root, which

Callers 15

resolveFunction · 0.85
path-test.tsFile · 0.85
resolveFunction · 0.85
maybeFileFunction · 0.85
findAssetsFunction · 0.85
resolvePathFunction · 0.85
getHeadFunction · 0.85
getStyleFunction · 0.85
bundleFunction · 0.85
getDependencyResolverFunction · 0.85
resolveRelativePathFunction · 0.85
resolveIdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected