import path from "node:path";
/**
 * Normalizes a file path by removing leading slashes.
 * This is necessary because path.join() treats leading slashes as absolute paths.
 *
 * @param filePath - The file path to normalize
 * @returns The normalized path without leading slash
 *
 * @example
 * normalizeRelativePath("/config/routes.json") // => "config/routes.json"
 * normalizeRelativePath("config/routes.json")  // => "config/routes.json"
 */
export function normalizeRelativePath(filePath) {
    return filePath.startsWith("/") ? filePath.slice(1) : filePath;
}
/**
 * Validates that a resolved path is within the allowed base directory.
 * This prevents path traversal attacks.
 *
 * @param resolvedPath - The absolute resolved path
 * @param baseDir - The base directory that the path must be within
 * @returns true if the path is safe, false otherwise
 *
 * @example
 * isPathSafe("/home/user/project/config", "/home/user/project") // => true
 * isPathSafe("/etc/passwd", "/home/user/project") // => false
 */
export function isPathSafe(resolvedPath, baseDir) {
    const normalizedResolved = path.resolve(resolvedPath);
    const normalizedBase = path.resolve(baseDir);
    return normalizedResolved.startsWith(normalizedBase);
}
/**
 * Normalizes a path for consistent display (always start with /)
 *
 * @param filePath - The file path to normalize
 * @returns The normalized path with leading slash
 */
export function normalizeDisplayPath(filePath) {
    return filePath.startsWith("/") ? filePath : `/${filePath}`;
}
//# sourceMappingURL=path.js.map