mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
Add format script to package.json and format with prettier.
This commit is contained in:
parent
61bd33845b
commit
be3b87e795
39 changed files with 1732 additions and 1734 deletions
|
@ -2,60 +2,60 @@ import { URL } from "../../client/url";
|
|||
import { rewriteJs } from "./js";
|
||||
|
||||
function canParseUrl(url: string, origin?: URL) {
|
||||
try {
|
||||
new URL(url, origin);
|
||||
try {
|
||||
new URL(url, origin);
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// something is broken with this but i didn't debug it
|
||||
export function encodeUrl(url: string | URL, origin?: URL) {
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
if (!origin) {
|
||||
origin = new URL(
|
||||
self.$scramjet.config.codec.decode(
|
||||
location.href.slice(
|
||||
(location.origin + self.$scramjet.config.prefix).length
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (!origin) {
|
||||
origin = new URL(
|
||||
self.$scramjet.config.codec.decode(
|
||||
location.href.slice(
|
||||
(location.origin + self.$scramjet.config.prefix).length,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// is this the correct behavior?
|
||||
if (!url) url = origin.href;
|
||||
// is this the correct behavior?
|
||||
if (!url) url = origin.href;
|
||||
|
||||
if (url.startsWith("javascript:")) {
|
||||
return "javascript:" + rewriteJs(url.slice("javascript:".length));
|
||||
} else if (/^(#|mailto|about|data)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url, origin)) {
|
||||
return (
|
||||
location.origin +
|
||||
self.$scramjet.config.prefix +
|
||||
self.$scramjet.config.codec.encode(new URL(url, origin).href)
|
||||
);
|
||||
}
|
||||
if (url.startsWith("javascript:")) {
|
||||
return "javascript:" + rewriteJs(url.slice("javascript:".length));
|
||||
} else if (/^(#|mailto|about|data)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url, origin)) {
|
||||
return (
|
||||
location.origin +
|
||||
self.$scramjet.config.prefix +
|
||||
self.$scramjet.config.codec.encode(new URL(url, origin).href)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// something is also broken with this but i didn't debug it
|
||||
export function decodeUrl(url: string | URL) {
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
if (url instanceof URL) {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
if (/^(#|about|data|mailto|javascript)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url)) {
|
||||
return self.$scramjet.config.codec.decode(
|
||||
url.slice((location.origin + self.$scramjet.config.prefix).length)
|
||||
);
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
if (/^(#|about|data|mailto|javascript)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url)) {
|
||||
return self.$scramjet.config.codec.decode(
|
||||
url.slice((location.origin + self.$scramjet.config.prefix).length),
|
||||
);
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue