Skip to content

Commit 1e71cb6

Browse files
committed
feat: support pkg@version format in search
Searching for `esbuild@0.25.12` or `@angular/core@^18` and pressing Enter now navigates directly to the package version page (or semver filter for ranges) instead of returning no results. Since in the previous commit I added support for linking to the package page with the a pre-filled semver version specifier in the query string to populate the version filter, this supports both exact versions and semver ranges in the search input. Closes #1416
1 parent c045062 commit 1e71cb6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/pages/search.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ function focusElement(el: HTMLElement) {
422422
el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
423423
}
424424
425+
// Parse "pkg@version" from search input (e.g. "esbuild@0.25.12", "@angular/core@^18")
426+
function parsePackageAtVersion(input: string): { name: string; version?: string } {
427+
const atIndex = input.startsWith('@') ? input.indexOf('@', 1) : input.indexOf('@')
428+
if (atIndex > 0) {
429+
const version = input.slice(atIndex + 1)
430+
if (version) return { name: input.slice(0, atIndex), version }
431+
}
432+
return { name: input }
433+
}
434+
425435
// Navigate to package page
426436
async function navigateToPackage(packageName: string) {
427437
await navigateTo(packageRoute(packageName))
@@ -460,6 +470,12 @@ function handleResultsKeydown(e: KeyboardEvent) {
460470
const inputValue = (document.activeElement as HTMLInputElement).value.trim()
461471
if (!inputValue) return
462472
473+
// Handle "pkg@version" format (e.g. "esbuild@0.25.12", "@angular/core@^18")
474+
const { name, version } = parsePackageAtVersion(inputValue)
475+
if (version) {
476+
return navigateTo(packageRoute(name, version))
477+
}
478+
463479
// Check if first result matches the input value exactly
464480
const firstResult = displayResults.value[0]
465481
if (firstResult?.package.name === inputValue) {

0 commit comments

Comments
 (0)