MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / getRelativePath

Function getRelativePath

src/utils/getRelativePath.ts:1–18  ·  view source on GitHub ↗
(from: string, to: string)

Source from the content-addressed store, hash-verified

1export default function getRelativePath(from: string, to: string): string {
2 const fromParts = from.split(/[/\\]/)
3 const toParts = to.split(/[/\\]/)
4
5 fromParts.pop() // get dirname
6
7 while (fromParts[0] === toParts[0]) {
8 fromParts.shift()
9 toParts.shift()
10 }
11
12 if (fromParts.length) {
13 let i = fromParts.length
14 while (i--) fromParts[i] = '..'
15 }
16
17 return fromParts.concat(toParts).join('/')
18}

Callers 2

generateDecodedMapMethod · 0.50
generateDecodedMapMethod · 0.50

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected