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

Function parsePackagePathname

packages/unpkg-files/src/lib/request-handler.ts:249–271  ·  view source on GitHub ↗
(pathname: string)

Source from the content-addressed store, hash-verified

247}
248
249function parsePackagePathname(pathname: string): {
250 package: string;
251 scope?: string;
252 version?: string;
253 filename?: string;
254} | null {
255 try {
256 pathname = decodeURIComponent(pathname);
257 } catch (e) {
258 console.error(`Failed to decode pathname: ${pathname}`);
259 }
260
261 let match = /^\/((?:(@[^/@]+)\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/.exec(pathname);
262
263 if (match == null) return null;
264
265 return {
266 package: match[1],
267 scope: match[2],
268 version: match[3],
269 filename: match[4],
270 };
271}

Callers 1

handleRequest_Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected