@@ -32,10 +32,10 @@ import type { PackageURL } from './package-url.js'
3232 * repository URL where the source code can be found.
3333 */
3434export interface RepositoryUrl {
35- /** The repository URL string. */
36- url : string
3735 /** The type of repository (version control system or web interface). */
3836 type : 'git' | 'hg' | 'svn' | 'web'
37+ /** The repository URL string. */
38+ url : string
3939}
4040
4141/**
@@ -45,10 +45,10 @@ export interface RepositoryUrl {
4545 * download URL where the package artifact can be obtained.
4646 */
4747export interface DownloadUrl {
48- /** The download URL string. */
49- url : string
5048 /** The type/format of the downloadable artifact. */
5149 type : 'tarball' | 'zip' | 'exe' | 'wheel' | 'jar' | 'gem' | 'other'
50+ /** The download URL string. */
51+ url : string
5252}
5353
5454/**
@@ -79,14 +79,14 @@ export class UrlConverter {
7979 switch ( type ) {
8080 case 'npm' :
8181 return {
82- url : `https://npmjs.com/package/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
8382 type : 'web' ,
83+ url : `https://npmjs.com/package/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
8484 }
8585
8686 case 'pypi' :
8787 return {
88- url : `https://pypi.org/project/${ name } /` ,
8988 type : 'web' ,
89+ url : `https://pypi.org/project/${ name } /` ,
9090 }
9191
9292 case 'maven' : {
@@ -95,87 +95,87 @@ export class UrlConverter {
9595 }
9696 const groupPath = namespace . replace ( / \. / g, '/' )
9797 return {
98- url : `https://repo1.maven.org/maven2/${ groupPath } /${ name } /` ,
9998 type : 'web' ,
99+ url : `https://repo1.maven.org/maven2/${ groupPath } /${ name } /` ,
100100 }
101101 }
102102
103103 case 'gem' :
104104 return {
105- url : `https://rubygems.org/gems/${ name } ` ,
106105 type : 'web' ,
106+ url : `https://rubygems.org/gems/${ name } ` ,
107107 }
108108
109109 case 'golang' :
110110 if ( ! namespace ) {
111111 return null
112112 }
113113 return {
114- url : `https://${ namespace } /${ name } ` ,
115114 type : 'git' ,
115+ url : `https://${ namespace } /${ name } ` ,
116116 }
117117
118118 case 'cargo' :
119119 return {
120- url : `https://crates.io/crates/${ name } ` ,
121120 type : 'web' ,
121+ url : `https://crates.io/crates/${ name } ` ,
122122 }
123123
124124 case 'nuget' :
125125 return {
126- url : `https://nuget.org/packages/${ name } /` ,
127126 type : 'web' ,
127+ url : `https://nuget.org/packages/${ name } /` ,
128128 }
129129
130130 case 'composer' :
131131 return {
132- url : `https://packagist.org/packages/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
133132 type : 'web' ,
133+ url : `https://packagist.org/packages/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
134134 }
135135
136136 case 'github' :
137137 if ( ! namespace ) {
138138 return null
139139 }
140140 return {
141- url : `https://github.com/${ namespace } /${ name } ` ,
142141 type : 'git' ,
142+ url : `https://github.com/${ namespace } /${ name } ` ,
143143 }
144144
145145 case 'gitlab' :
146146 if ( ! namespace ) {
147147 return null
148148 }
149149 return {
150- url : `https://gitlab.com/${ namespace } /${ name } ` ,
151150 type : 'git' ,
151+ url : `https://gitlab.com/${ namespace } /${ name } ` ,
152152 }
153153
154154 case 'bitbucket' :
155155 if ( ! namespace ) {
156156 return null
157157 }
158158 return {
159- url : `https://bitbucket.org/${ namespace } /${ name } ` ,
160159 type : 'git' ,
160+ url : `https://bitbucket.org/${ namespace } /${ name } ` ,
161161 }
162162
163163 case 'hex' :
164164 return {
165- url : `https://hex.pm/packages/${ name } ` ,
166165 type : 'web' ,
166+ url : `https://hex.pm/packages/${ name } ` ,
167167 }
168168
169169 case 'pub' :
170170 return {
171- url : `https://pub.dev/packages/${ name } ` ,
172171 type : 'web' ,
172+ url : `https://pub.dev/packages/${ name } ` ,
173173 }
174174
175175 case 'luarocks' :
176176 return {
177- url : `https://luarocks.org/modules/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
178177 type : 'web' ,
178+ url : `https://luarocks.org/modules/${ namespace ? `${ namespace } /` : '' } ${ name } ` ,
179179 }
180180
181181 default :
@@ -201,15 +201,15 @@ export class UrlConverter {
201201 case 'npm' : {
202202 const npmName = namespace ? `${ namespace } /${ name } ` : name
203203 return {
204- url : `https://registry.npmjs.org/${ npmName } /-/${ name } -${ version } .tgz` ,
205204 type : 'tarball' ,
205+ url : `https://registry.npmjs.org/${ npmName } /-/${ name } -${ version } .tgz` ,
206206 }
207207 }
208208
209209 case 'pypi' :
210210 return {
211- url : `https://pypi.org/simple/${ name } /` ,
212211 type : 'wheel' ,
212+ url : `https://pypi.org/simple/${ name } /` ,
213213 }
214214
215215 case 'maven' : {
@@ -218,57 +218,57 @@ export class UrlConverter {
218218 }
219219 const groupPath = namespace . replace ( / \. / g, '/' )
220220 return {
221- url : `https://repo1.maven.org/maven2/${ groupPath } /${ name } /${ version } /${ name } -${ version } .jar` ,
222221 type : 'jar' ,
222+ url : `https://repo1.maven.org/maven2/${ groupPath } /${ name } /${ version } /${ name } -${ version } .jar` ,
223223 }
224224 }
225225
226226 case 'gem' :
227227 return {
228- url : `https://rubygems.org/downloads/${ name } -${ version } .gem` ,
229228 type : 'gem' ,
229+ url : `https://rubygems.org/downloads/${ name } -${ version } .gem` ,
230230 }
231231
232232 case 'cargo' :
233233 return {
234- url : `https://crates.io/api/v1/crates/${ name } /${ version } /download` ,
235234 type : 'tarball' ,
235+ url : `https://crates.io/api/v1/crates/${ name } /${ version } /download` ,
236236 }
237237
238238 case 'nuget' :
239239 return {
240- url : `https://nuget.org/packages/${ name } /${ version } /download` ,
241240 type : 'zip' ,
241+ url : `https://nuget.org/packages/${ name } /${ version } /download` ,
242242 }
243243
244244 case 'composer' :
245245 if ( ! namespace ) {
246246 return null
247247 }
248248 return {
249- url : `https://repo.packagist.org/p2/${ namespace } /${ name } .json` ,
250249 type : 'other' ,
250+ url : `https://repo.packagist.org/p2/${ namespace } /${ name } .json` ,
251251 }
252252
253253 case 'hex' :
254254 return {
255- url : `https://repo.hex.pm/tarballs/${ name } -${ version } .tar` ,
256255 type : 'tarball' ,
256+ url : `https://repo.hex.pm/tarballs/${ name } -${ version } .tar` ,
257257 }
258258
259259 case 'pub' :
260260 return {
261- url : `https://pub.dev/packages/${ name } /versions/${ version } .tar.gz` ,
262261 type : 'tarball' ,
262+ url : `https://pub.dev/packages/${ name } /versions/${ version } .tar.gz` ,
263263 }
264264
265265 case 'golang' :
266266 if ( ! namespace ) {
267267 return null
268268 }
269269 return {
270- url : `https://proxy.golang.org/${ namespace } /${ name } /@v/${ version } .zip` ,
271270 type : 'zip' ,
271+ url : `https://proxy.golang.org/${ namespace } /${ name } /@v/${ version } .zip` ,
272272 }
273273
274274 default :
@@ -283,12 +283,12 @@ export class UrlConverter {
283283 * in a single call, useful when you need to check all URL options.
284284 */
285285 static getAllUrls ( purl : PackageURL ) : {
286- repository : RepositoryUrl | null
287286 download : DownloadUrl | null
287+ repository : RepositoryUrl | null
288288 } {
289289 return {
290- repository : this . toRepositoryUrl ( purl ) ,
291290 download : this . toDownloadUrl ( purl ) ,
291+ repository : this . toRepositoryUrl ( purl ) ,
292292 }
293293 }
294294
0 commit comments