Files
automaker/libs/utils/src/path-utils.ts
SuperComboGamer 584f5a3426 Merge main into massive-terminal-upgrade
Resolves merge conflicts:
- apps/server/src/routes/terminal/common.ts: Keep randomBytes import, use @automaker/utils for createLogger
- apps/ui/eslint.config.mjs: Use main's explicit globals list with XMLHttpRequest and MediaQueryListEvent additions
- apps/ui/src/components/views/terminal-view.tsx: Keep our terminal improvements (killAllSessions, beforeunload, better error handling)
- apps/ui/src/config/terminal-themes.ts: Keep our search highlight colors for all themes
- apps/ui/src/store/app-store.ts: Keep our terminal settings persistence improvements (merge function)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 20:27:44 -05:00

52 lines
1.7 KiB
TypeScript

/**
* Path Utilities - Cross-platform path manipulation helpers
*
* Provides functions for normalizing and comparing file system paths
* across different operating systems (Windows, macOS, Linux).
*/
/**
* Normalize a path by converting backslashes to forward slashes
*
* This ensures consistent path representation across platforms:
* - Windows: C:\Users\foo\bar -> C:/Users/foo/bar
* - Unix: /home/foo/bar -> /home/foo/bar (unchanged)
*
* @param p - Path string to normalize
* @returns Normalized path with forward slashes
*
* @example
* ```typescript
* normalizePath("C:\\Users\\foo\\bar"); // "C:/Users/foo/bar"
* normalizePath("/home/foo/bar"); // "/home/foo/bar"
* ```
*/
export function normalizePath(p: string): string {
return p.replace(/\\/g, '/');
}
/**
* Compare two paths for equality after normalization
*
* Handles null/undefined values and normalizes paths before comparison.
* Useful for checking if two paths refer to the same location regardless
* of platform-specific path separators.
*
* @param p1 - First path to compare (or null/undefined)
* @param p2 - Second path to compare (or null/undefined)
* @returns true if paths are equal (or both null/undefined), false otherwise
*
* @example
* ```typescript
* pathsEqual("C:\\foo\\bar", "C:/foo/bar"); // true
* pathsEqual("/home/user", "/home/user"); // true
* pathsEqual("/home/user", "/home/other"); // false
* pathsEqual(null, undefined); // false
* pathsEqual(null, null); // true
* ```
*/
export function pathsEqual(p1: string | undefined | null, p2: string | undefined | null): boolean {
if (!p1 || !p2) return p1 === p2;
return normalizePath(p1) === normalizePath(p2);
}