(path: string)
| 1 | export function normalizePath(path: string): string { |
| 2 | const normalized = path.replace(/\\/g, '/') |
| 3 | const isAbsolute = normalized.startsWith('/') |
| 4 | const parts: Array<string> = [] |
| 5 | |
| 6 | for (const part of normalized.split('/')) { |
| 7 | if (!part || part === '.') { |
| 8 | continue |
| 9 | } |
| 10 | if (part === '..') { |
| 11 | if (parts.length && parts[parts.length - 1] !== '..') { |
| 12 | parts.pop() |
| 13 | } else if (!isAbsolute) { |
| 14 | parts.push(part) |
| 15 | } |
| 16 | continue |
| 17 | } |
| 18 | parts.push(part) |
| 19 | } |
| 20 | |
| 21 | const joined = parts.join('/') |
| 22 | if (isAbsolute) { |
| 23 | return joined ? `/${joined}` : '/' |
| 24 | } |
| 25 | |
| 26 | return joined || '.' |
| 27 | } |
| 28 | |
| 29 | export function joinPaths(...paths: Array<string | undefined>): string { |
| 30 | const filtered = paths.filter( |
no test coverage detected