continue-custom/core/util/pathToUri.ts
2025-01-16 15:20:20 -08:00

21 lines
516 B
TypeScript

import { fileURLToPath, pathToFileURL } from "url";
import * as 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;
}
}