Files
Desktop/ts/util/isPathInside.node.ts
Fedor Indutny 44076ece79 Rename files
2025-10-16 23:45:44 -07:00

20 lines
572 B
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// This is inspired by the `is-path-inside` module on npm.
import * as path from 'node: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)
);
}