* Normalize a path by resolving . and .. segments
(path: string)
| 28 | * Normalize a path by resolving . and .. segments |
| 29 | */ |
| 30 | function normalizePath(path: string): string { |
| 31 | const parts = path.split('/') |
| 32 | const result: string[] = [] |
| 33 | |
| 34 | for (const part of parts) { |
| 35 | if (part === '.' || part === '') { |
| 36 | continue |
| 37 | } |
| 38 | if (part === '..') { |
| 39 | result.pop() |
| 40 | } else { |
| 41 | result.push(part) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return result.join('/') |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the directory of a file path. |
no outgoing calls
no test coverage detected