(dirPath: string, filePath: string)
| 138 | * isPathInsideDir("/home/user/project", "/home/user/other/file.ts") // false |
| 139 | */ |
| 140 | export function isPathInsideDir(dirPath: string, filePath: string): boolean { |
| 141 | const resolvedDir = path.resolve(dirPath); |
| 142 | const resolvedFile = path.resolve(filePath); |
| 143 | const relative = path.relative(resolvedDir, resolvedFile); |
| 144 | |
| 145 | return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative)); |
| 146 | } |
no test coverage detected