@@ -72,13 +72,17 @@ export interface CheckNameResult {
7272
7373const NPM_REGISTRY = 'https://registry.npmjs.org'
7474
75- export async function checkPackageExists ( name : string ) : Promise < boolean > {
75+ export async function checkPackageExists (
76+ name : string ,
77+ options : Parameters < typeof $fetch > [ 1 ] = { } ,
78+ ) : Promise < boolean > {
7679 try {
7780 const encodedName = name . startsWith ( '@' )
7881 ? `@${ encodeURIComponent ( name . slice ( 1 ) ) } `
7982 : encodeURIComponent ( name )
8083
8184 await $fetch ( `${ NPM_REGISTRY } /${ encodedName } ` , {
85+ ...options ,
8286 method : 'HEAD' ,
8387 } )
8488 return true
@@ -87,7 +91,10 @@ export async function checkPackageExists(name: string): Promise<boolean> {
8791 }
8892}
8993
90- export async function findSimilarPackages ( name : string ) : Promise < SimilarPackage [ ] > {
94+ export async function findSimilarPackages (
95+ name : string ,
96+ options : Parameters < typeof $fetch > [ 1 ] = { } ,
97+ ) : Promise < SimilarPackage [ ] > {
9198 const normalized = normalizePackageName ( name )
9299 const similar : SimilarPackage [ ] = [ ]
93100
@@ -99,7 +106,7 @@ export async function findSimilarPackages(name: string): Promise<SimilarPackage[
99106 description ?: string
100107 }
101108 } >
102- } > ( `${ NPM_REGISTRY } /-/v1/search?text=${ encodeURIComponent ( name ) } &size=20` )
109+ } > ( `${ NPM_REGISTRY } /-/v1/search?text=${ encodeURIComponent ( name ) } &size=20` , options )
103110
104111 for ( const obj of searchResponse . objects ) {
105112 const pkgName = obj . package . name
@@ -153,7 +160,10 @@ export async function findSimilarPackages(name: string): Promise<SimilarPackage[
153160 }
154161}
155162
156- export async function checkPackageName ( name : string ) : Promise < CheckNameResult > {
163+ export async function checkPackageName (
164+ name : string ,
165+ options : Parameters < typeof $fetch > [ 1 ] = { } ,
166+ ) : Promise < CheckNameResult > {
157167 const validation = validatePackageName ( name )
158168 const valid = validation . validForNewPackages === true
159169
@@ -177,8 +187,8 @@ export async function checkPackageName(name: string): Promise<CheckNameResult> {
177187
178188 // Check if package exists and find similar packages in parallel
179189 const [ exists , similarPackages ] = await Promise . all ( [
180- checkPackageExists ( name ) ,
181- findSimilarPackages ( name ) ,
190+ checkPackageExists ( name , options ) ,
191+ findSimilarPackages ( name , options ) ,
182192 ] )
183193
184194 result . available = ! exists
0 commit comments