@@ -33,6 +33,24 @@ const updateUrlPage = debounce((page: number) => {
3333const { model : searchQuery, provider : searchProvider } = useGlobalSearch ()
3434const query = computed (() => searchQuery .value )
3535
36+ // Parses the raw search query to extract package info, such as scope, name, version.
37+ // Uses this info to provide a strippedQuery (the query, but without version info) that is used for searching.
38+ const parsedQuery = computed (() => {
39+ const q = query .value .trim ()
40+ // Regex matches a (un)scoped package and optionally extracts versioning info using the following syntax: @scope/specifier@version
41+ // It makes use of 4 capture groups to extract this info.
42+ const match = q .match (/ ^ (?:@([^ /] + )\/ )? ([^ /@ ] + )(?:@([^ ] * ))? (. * )/ )
43+ if (! match ) return { scope: null , name: q , version: null , strippedQuery: q }
44+
45+ const [, scope, specifier, version, trailing] = match
46+ // Reconstruct the query without the version info, essentially stripping the version data:
47+ // anything directly after the @ for the version specifier is stripped.
48+ const name = scope ? ` @${scope }/${specifier } ` : (specifier ?? ' ' )
49+ const strippedQuery = ` ${name } ${trailing ?? ' ' } ` .trim ()
50+
51+ return { scope: scope ?? null , name: name , version: version || null , strippedQuery }
52+ })
53+
3654// Track if page just loaded (for hiding "Searching..." during view transition)
3755const hasInteracted = shallowRef (false )
3856onMounted (() => {
0 commit comments