(from: string, to: string)
| 61 | } |
| 62 | |
| 63 | export function relative(from: string, to: string): string { |
| 64 | const fromParts = from.split(ANY_SLASH_REGEX).filter(Boolean); |
| 65 | const toParts = to.split(ANY_SLASH_REGEX).filter(Boolean); |
| 66 | |
| 67 | if (fromParts[0] === '.') fromParts.shift(); |
| 68 | if (toParts[0] === '.') toParts.shift(); |
| 69 | |
| 70 | while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) { |
| 71 | fromParts.shift(); |
| 72 | toParts.shift(); |
| 73 | } |
| 74 | |
| 75 | while (toParts[0] === '..' && fromParts.length > 0) { |
| 76 | toParts.shift(); |
| 77 | fromParts.pop(); |
| 78 | } |
| 79 | |
| 80 | while (fromParts.pop()) { |
| 81 | toParts.unshift('..'); |
| 82 | } |
| 83 | |
| 84 | return toParts.join('/'); |
| 85 | } |
| 86 | |
| 87 | export function resolve(...paths: string[]): string { |
| 88 | let parts: string[] = []; |
no outgoing calls
no test coverage detected
searching dependent graphs…