| 45 | } |
| 46 | |
| 47 | function normalizePathSegments(parts: string[], absolute = false): string { |
| 48 | const normalized: string[] = []; |
| 49 | for (const part of parts) { |
| 50 | if (part === '..') { |
| 51 | if (normalized.length > 0 && normalized[normalized.length - 1] !== '..') { |
| 52 | normalized.pop(); |
| 53 | } else if (!absolute) { |
| 54 | normalized.push('..'); |
| 55 | } |
| 56 | } else if (part !== '.' && part !== '') { |
| 57 | normalized.push(part); |
| 58 | } |
| 59 | } |
| 60 | return normalized.join('/'); |
| 61 | } |
| 62 | |
| 63 | export function relative(from: string, to: string): string { |
| 64 | const fromParts = from.split(ANY_SLASH_REGEX).filter(Boolean); |