MCPcopy
hub / github.com/npmx-dev/npmx.dev / getPackageName

Function getPackageName

server/utils/code-highlight.ts:118–133  ·  view source on GitHub ↗

* Extract the package name from a module specifier (handles scoped packages and subpaths)

(specifier: string)

Source from the content-addressed store, hash-verified

116 * Extract the package name from a module specifier (handles scoped packages and subpaths)
117 */
118function getPackageName(specifier: string): string {
119 const pkg = specifier.replace(/^['"]|['"]$/g, '').trim()
120 // Scoped package: @scope/name or @scope/name/subpath
121 if (pkg.startsWith('@')) {
122 const parts = pkg.split('/')
123 if (parts[0] && parts[1]) {
124 return `${parts[0]}/${parts[1]}`
125 }
126 }
127 // Regular package: name or name/subpath
128 const firstSlash = pkg.indexOf('/')
129 if (firstSlash > 0) {
130 return pkg.substring(0, firstSlash)
131 }
132 return pkg
133}
134
135/**
136 * Resolved dependency info for linking imports to specific versions

Callers 1

getHrefFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected