minor refactor, cleanup

This commit is contained in:
Nystik
2026-03-11 22:08:30 +01:00
parent 2b9ebf1fbd
commit 9789be6d70
38 changed files with 259 additions and 379 deletions

View File

@@ -1,22 +1,19 @@
// URL shim
// Obsidian uses: pathToFileURL, fileURLToPath, URL, URLSearchParams
export const urlShim = {
URL: globalThis.URL,
URLSearchParams: globalThis.URLSearchParams,
pathToFileURL(p) {
// Return an object with .href matching Node's url.pathToFileURL behavior
const encoded = encodeURI(p.replace(/\\/g, '/'));
const href = 'file:///' + encoded.replace(/^\/+/, '');
const encoded = encodeURI(p.replace(/\\/g, "/"));
const href = "file:///" + encoded.replace(/^\/+/, "");
return { href, toString: () => href };
},
fileURLToPath(url) {
let str = typeof url === 'string' ? url : url.href || url.toString();
if (str.startsWith('file:///')) {
let str = typeof url === "string" ? url : url.href || url.toString();
if (str.startsWith("file:///")) {
str = str.slice(8);
} else if (str.startsWith('file://')) {
} else if (str.startsWith("file://")) {
str = str.slice(7);
}
return decodeURI(str);