2026-03-07 18:11:46 +01:00
|
|
|
export const urlShim = {
|
|
|
|
|
URL: globalThis.URL,
|
|
|
|
|
URLSearchParams: globalThis.URLSearchParams,
|
|
|
|
|
|
|
|
|
|
pathToFileURL(p) {
|
|
|
|
|
// Return an object with .href matching Node's url.pathToFileURL behavior
|
2026-03-11 22:08:30 +01:00
|
|
|
const encoded = encodeURI(p.replace(/\\/g, "/"));
|
|
|
|
|
const href = "file:///" + encoded.replace(/^\/+/, "");
|
2026-03-17 12:38:30 +01:00
|
|
|
|
2026-03-07 18:11:46 +01:00
|
|
|
return { href, toString: () => href };
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fileURLToPath(url) {
|
2026-03-11 22:08:30 +01:00
|
|
|
let str = typeof url === "string" ? url : url.href || url.toString();
|
2026-03-17 12:38:30 +01:00
|
|
|
|
2026-03-11 22:08:30 +01:00
|
|
|
if (str.startsWith("file:///")) {
|
2026-03-07 18:11:46 +01:00
|
|
|
str = str.slice(8);
|
2026-03-11 22:08:30 +01:00
|
|
|
} else if (str.startsWith("file://")) {
|
2026-03-07 18:11:46 +01:00
|
|
|
str = str.slice(7);
|
|
|
|
|
}
|
2026-03-17 12:38:30 +01:00
|
|
|
|
2026-03-07 18:11:46 +01:00
|
|
|
return decodeURI(str);
|
|
|
|
|
},
|
|
|
|
|
};
|