1
2
3
4
5
6
7
8
9
10
11
12
13
export function extractValInfo(url: string | URL) {
const { pathname, search } = new URL(url);
const [author, filename] = pathname.split("/").slice(-2);
const [name] = filename.split(".");
const version = new URLSearchParams(search).get("v");
const slug = `${author}/${name}`;
const htmlUrl = `https://val.town/v/${author}/${name}`;
const rawUrl = `https://esm.town/v/${author}/${name}`;
const embedUrl = `https://val.town/embed/${author}/${name}`;
const httpEndpoint = `https://${author}-${name}.web.val.run`;
return { author, name, version, slug, htmlUrl, rawUrl, httpEndpoint, embedUrl };
}