@@ -14,6 +14,27 @@ async function fetchNpmPackage(name: string): Promise<Packument> {
1414 return await $fetch < Packument > ( `${ NPM_REGISTRY } /${ encodedName } ` )
1515}
1616
17+ async function searchNpmPackages (
18+ query : string ,
19+ options : {
20+ size ?: number
21+ from ?: number
22+ quality ?: number
23+ popularity ?: number
24+ maintenance ?: number
25+ } = { } ,
26+ ) : Promise < NpmSearchResponse > {
27+ const params = new URLSearchParams ( )
28+ params . set ( 'text' , query )
29+ if ( options . size ) params . set ( 'size' , String ( options . size ) )
30+ if ( options . from ) params . set ( 'from' , String ( options . from ) )
31+ if ( options . quality !== undefined ) params . set ( 'quality' , String ( options . quality ) )
32+ if ( options . popularity !== undefined ) params . set ( 'popularity' , String ( options . popularity ) )
33+ if ( options . maintenance !== undefined ) params . set ( 'maintenance' , String ( options . maintenance ) )
34+
35+ return await $fetch < NpmSearchResponse > ( `${ NPM_REGISTRY } /-/v1/search?${ params . toString ( ) } ` )
36+ }
37+
1738async function fetchNpmDownloads (
1839 packageName : string ,
1940 period : 'last-day' | 'last-week' | 'last-month' | 'last-year' = 'last-week' ,
@@ -120,7 +141,6 @@ export function useNpmSearch(
120141 from ?: number
121142 } > = { } ,
122143) {
123- const registry = useNpmRegistry ( )
124144 let lastSearch : NpmSearchResponse | undefined = undefined
125145
126146 return useLazyAsyncData (
@@ -130,7 +150,7 @@ export function useNpmSearch(
130150 if ( ! q . trim ( ) ) {
131151 return Promise . resolve ( emptySearchResponse )
132152 }
133- return lastSearch = await registry . searchPackages ( q , toValue ( options ) )
153+ return lastSearch = await searchNpmPackages ( q , toValue ( options ) )
134154 } ,
135155 { default : ( ) => lastSearch || emptySearchResponse } ,
136156 )
0 commit comments