MCPcopy
hub / github.com/unpkg/unpkg / parsePackagePathname

Function parsePackagePathname

packages/unpkg-worker/src/lib/pkg-pathname.ts:1–23  ·  view source on GitHub ↗
(pathname: string)

Source from the content-addressed store, hash-verified

1export function parsePackagePathname(pathname: string): {
2 package: string;
3 scope?: string;
4 version?: string;
5 filename?: string;
6} | null {
7 try {
8 pathname = decodeURIComponent(pathname);
9 } catch (e) {
10 console.error(`Failed to decode pathname: ${pathname}`);
11 }
12
13 let match = /^\/((?:(@[^/@]+)\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/.exec(pathname);
14
15 if (match == null) return null;
16
17 return {
18 package: match[1],
19 scope: match[2],
20 version: match[3],
21 filename: match[4],
22 };
23}

Callers 2

handleRequestFunction · 0.90
handleRequestFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected