(path: string | URL)
| 42 | * @returns The normalized path. |
| 43 | */ |
| 44 | export function normalize(path: string | URL): string { |
| 45 | if (path instanceof URL) { |
| 46 | path = fromFileUrl(path); |
| 47 | } |
| 48 | assertArg(path); |
| 49 | |
| 50 | const isAbsolute = isPosixPathSeparator(path.charCodeAt(0)); |
| 51 | const trailingSeparator = isPosixPathSeparator( |
| 52 | path.charCodeAt(path.length - 1), |
| 53 | ); |
| 54 | |
| 55 | // Normalize the path |
| 56 | path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator); |
| 57 | |
| 58 | if (path.length === 0 && !isAbsolute) path = "."; |
| 59 | if (path.length > 0 && trailingSeparator) path += "/"; |
| 60 | |
| 61 | if (isAbsolute) return `/${path}`; |
| 62 | return path; |
| 63 | } |
no test coverage detected