queue
Viewing readonly version: 67View latest version
Script
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
interface ImportMetaUrl {
username: string;
projectName: string;
version: string;
branchName: string;
path: string;
}
export function parseImportMeta(url: string): ImportMetaUrl {
const pattern = /^https:\/\/esm\.town\/v\/([^/]+)\/([^@]+)@(\d+)-(.+?)(\/.*)?$/;
const match = url.match(pattern);
if (!match) {
throw new Error(`Invalid ESM Town URL format: ${url}`);
}
const [, username, projectName, version, branchName, path = ""] = match;
return {
username,
projectName,
version,
branchName,
path: path.substring(1), // Remove leading slash
};
}
// // Example usage:
// const urls = [
// "https://esm.town/v/maxm/queue@11-main/runMigrations",
// "https://esm.town/v/user/project@1-feature-branch-name/path/asdf/asfd/asdf/asfd",
// "https://esm.town/v/dev/app@22-complex-branch-with-dashes",
// ];
// urls.forEach(url => console.log(parseEsmTownUrl(url)));