(source: string, target: string)
| 8 | * from the root. |
| 9 | */ |
| 10 | export 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 |
no outgoing calls
no test coverage detected