MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / parseScopedPackageWithVersion

Function parseScopedPackageWithVersion

modules/runtime/server/cache.ts:72–102  ·  view source on GitHub ↗

* Parse a scoped package name with optional version. * Handles formats like: @scope/name, @scope/name@version, name, name@version

(input: string)

Source from the content-addressed store, hash-verified

70 * Handles formats like: @scope/name, @scope/name@version, name, name@version
71 */
72function parseScopedPackageWithVersion(input: string): { name: string; version?: string } {
73 if (input.startsWith('@')) {
74 // Scoped package: @scope/name or @scope/name@version
75 const slashIndex = input.indexOf('/')
76 if (slashIndex === -1) {
77 // Invalid format like just "@scope"
78 return { name: input }
79 }
80 const afterSlash = input.slice(slashIndex + 1)
81 const atIndex = afterSlash.indexOf('@')
82 if (atIndex === -1) {
83 // @scope/name (no version)
84 return { name: input }
85 }
86 // @scope/name@version
87 return {
88 name: input.slice(0, slashIndex + 1 + atIndex),
89 version: afterSlash.slice(atIndex + 1),
90 }
91 }
92
93 // Unscoped package: name or name@version
94 const atIndex = input.indexOf('@')
95 if (atIndex === -1) {
96 return { name: input }
97 }
98 return {
99 name: input.slice(0, atIndex),
100 version: input.slice(atIndex + 1),
101 }
102}
103
104function getMockForUrl(url: string): MockResult | null {
105 const urlObj = URL.parse(url)

Callers 1

handleJsdelivrDataApiFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected