Elffuss BraidHub

kikocis/continue public

3ff29c567dd0 · 797 BRawPermalink
1import { fileURLToPath, pathToFileURL } from "url";
2
3import * as URI from "uri-js";
4
5// CAN ONLY BE USED IN CORE
6
7// Converts a local path to a file:/// URI
8export function localPathToUri(path: string) {
9 // This may incidentally solve bugs, but it is primarily here to warn us if we accidentally try to double-convert. It doesn't handle other URI schemes.
10 if (path.startsWith("file://")) {
11 console.warn("localPathToUri: path already starts with file://");
12 return path;
13 }
14 const url = pathToFileURL(path);
15 return URI.normalize(url.toString());
16}
17
18export function localPathOrUriToPath(localPathOrUri: string): string {
19 try {
20 return fileURLToPath(localPathOrUri);
21 } catch (e) {
22 // console.log("Received local filepath", localPathOrUri);
23
24 return localPathOrUri;
25 }
26}