* Extract basename from path (OS-aware) * * @param filePath - Path to extract basename from * @returns The final component of the path * * @example * // Unix * basename("/home/user/project") // => "project" * * // Windows * basename("C:\\Users\\user\\project") // => "pr
(filePath: string)
| 54 | * basename("C:\\Users\\user\\project") // => "project" |
| 55 | */ |
| 56 | static basename(filePath: string): string { |
| 57 | if (!filePath || typeof filePath !== "string") { |
| 58 | return filePath; |
| 59 | } |
| 60 | |
| 61 | const lastSlash = isWindowsPlatform() |
| 62 | ? Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) |
| 63 | : filePath.lastIndexOf("/"); |
| 64 | if (lastSlash === -1) { |
| 65 | return filePath; |
| 66 | } |
| 67 | return filePath.slice(lastSlash + 1); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Split path into components (OS-aware) |
no test coverage detected