(from: string, to: string)
| 1 | export 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 | } |
no test coverage detected