mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
17 lines
471 B
TypeScript
17 lines
471 B
TypeScript
import * as path from 'node:path';
|
|
|
|
/**
|
|
* Checks if the given childPath is contained within the parentPath. Resolves
|
|
* the paths before comparing them, so that relative paths are also supported.
|
|
*/
|
|
export function isContainedWithin(parentPath: string, childPath: string): boolean {
|
|
parentPath = path.resolve(parentPath);
|
|
childPath = path.resolve(childPath);
|
|
|
|
if (parentPath === childPath) {
|
|
return true;
|
|
}
|
|
|
|
return childPath.startsWith(parentPath + path.sep);
|
|
}
|