continue-custom/core/util/pathToUri.ts
2024-12-13 15:55:22 -08:00

21 lines
507 B
TypeScript

import { fileURLToPath, pathToFileURL } from "url";
import URI from "uri-js";
// CAN ONLY BE USED IN CORE
// Converts a local path to a file:// URI
export function localPathToUri(path: string) {
const url = pathToFileURL(path);
return URI.normalize(url.toString());
}
export function localPathOrUriToPath(localPathOrUri: string): string {
try {
return fileURLToPath(localPathOrUri);
} catch (e) {
console.log("Received local filepath", localPathOrUri);
return localPathOrUri;
}
}