* Parse a scoped package name with optional version. * Handles formats like: @scope/name, @scope/name@version, name, name@version
(input: string)
| 70 | * Handles formats like: @scope/name, @scope/name@version, name, name@version |
| 71 | */ |
| 72 | function 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 | |
| 104 | function getMockForUrl(url: string): MockResult | null { |
| 105 | const urlObj = URL.parse(url) |
no outgoing calls
no test coverage detected