UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

44 lines 1.92 kB
/** * Converts a file:// URL to a portable path format that can be used with path-module (POSIX-only). * * This function is designed to work with isomorphic code that uses path-module, * which only supports POSIX paths. The key insight is that by stripping the `file://` * prefix and normalizing backslashes to forward slashes, we get a path that: * - On Unix: `/home/user/file.ts` - works directly with path-module * - On Windows: `/C:/Users/file.ts` - also works with path-module because it starts with `/` * * The resulting path is NOT a valid filesystem path on Windows, but it's a valid * POSIX-style path for path manipulation. Use `fileURLToPath` from the `url` module * when you need to access the actual filesystem. * * @param fileUrl - A file:// URL or absolute path (with forward slashes) * @returns A portable path starting with `/` that works with path-module * * @example * // Unix file URL * fileUrlToPortablePath('file:///home/user/file.ts') // => '/home/user/file.ts' * * // Windows file URL * fileUrlToPortablePath('file:///C:/Users/file.ts') // => '/C:/Users/file.ts' * * // Already a portable path (passthrough) * fileUrlToPortablePath('/home/user/file.ts') // => '/home/user/file.ts' */ export declare function fileUrlToPortablePath(fileUrl: string): string; /** * Converts a portable path back to a file:// URL. * * This is the inverse of `fileUrlToPortablePath`. It takes a portable path * (which always starts with `/`) and converts it back to a proper file:// URL. * * @param portablePath - A portable path starting with `/` * @returns A file:// URL * * @example * // Unix path * portablePathToFileUrl('/home/user/file.ts') // => 'file:///home/user/file.ts' * * // Windows path (portable format) * portablePathToFileUrl('/C:/Users/file.ts') // => 'file:///C:/Users/file.ts' */ export declare function portablePathToFileUrl(portablePath: string): string;