Improve nested path detection across app
This commit is contained in:
parent
57d206a344
commit
f8fc23a7a3
5 changed files with 169 additions and 12 deletions
16
ts/util/isPathInside.ts
Normal file
16
ts/util/isPathInside.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// This is inspired by the `is-path-inside` module on npm.
|
||||
import * as path from 'path';
|
||||
|
||||
export function isPathInside(childPath: string, parentPath: string): boolean {
|
||||
const childPathResolved = path.resolve(childPath);
|
||||
|
||||
let parentPathResolved = path.resolve(parentPath);
|
||||
if (!parentPathResolved.endsWith(path.sep)) {
|
||||
parentPathResolved += path.sep;
|
||||
}
|
||||
|
||||
return (
|
||||
childPathResolved !== parentPathResolved &&
|
||||
childPathResolved.startsWith(parentPathResolved)
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue