* Check if a file path is under a given root directory.
(filePath, rootPath)
| 83 | * Check if a file path is under a given root directory. |
| 84 | */ |
| 85 | function isUnderRoot(filePath, rootPath) { |
| 86 | const normalizedFile = filePath.replace(/\\/g, '/'); |
| 87 | const normalizedRoot = rootPath.replace(/\\/g, '/').replace(/\/$/, '') + '/'; |
| 88 | return normalizedFile.startsWith(normalizedRoot); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the directory of a file path, normalized to forward slashes. |