1
- const reservedPaths = require ( 'github-reserved-names/reserved-names.json' ) ;
1
+ import reservedNames from 'github-reserved-names/reserved-names.json' with { type : 'json' } ;
2
2
3
3
const patchDiffRegex = / [ . ] ( p a t c h | d i f f ) $ / ;
4
4
const releaseRegex = / ^ r e l e a s e s [ / ] t a g [ / ] ( [ ^ / ] + ) / ;
@@ -43,7 +43,7 @@ function joinValues(array, delimiter = '/') {
43
43
return array . filter ( Boolean ) . join ( delimiter ) ;
44
44
}
45
45
46
- function shortenURL ( href , currentUrl = 'https://github.com' ) {
46
+ function shortenRepoUrl ( href , currentUrl = 'https://github.com' ) {
47
47
if ( ! href ) {
48
48
return ;
49
49
}
@@ -101,20 +101,20 @@ function shortenURL(href, currentUrl = 'https://github.com') {
101
101
102
102
const isLocal = origin === currentUrl . origin ;
103
103
const isThisRepo = ( isLocal || isRaw || isRedirection ) && currentRepo === `${ user } /${ repo } ` ;
104
- const isReserved = reservedPaths . includes ( user ) ;
104
+ const isReserved = reservedNames . includes ( user ) ;
105
105
const isDependents = dependentsRegex . test ( repoPath ) ;
106
106
const isDependencies = dependenciesRegex . test ( repoPath ) ;
107
107
const [ , diffOrPatch ] = repoPath . match ( patchDiffRegex ) || [ ] ;
108
108
const [ , release ] = repoPath . match ( releaseRegex ) || [ ] ;
109
- const [ , releaseTag , releaseTagExt ] = repoPath . match ( releaseArchiveRegex ) || [ ] ;
109
+ const [ , releaseTag , releaseTagExtension ] = repoPath . match ( releaseArchiveRegex ) || [ ] ;
110
110
const [ , downloadTag , downloadFilename ] = repoPath . match ( releaseDownloadRegex ) || [ ] ;
111
111
const [ , label ] = repoPath . match ( labelRegex ) || [ ] ;
112
112
const [ , compare ] = repoPath . match ( compareRegex ) || [ ] ;
113
113
const { pull, pullPage, pullPartialStart, pullPartialEnd} = repoPath . match ( pullRegex ) ?. groups ?? { } ;
114
114
const [ , issue ] = isRedirection ? repoPath . match ( issueRegex ) || [ ] : [ ] ;
115
115
const [ , commit ] = isRedirection ? repoPath . match ( commitRegex ) || [ ] : [ ] ;
116
116
const [ , wiki ] = repoPath . match ( wikiRegex ) || [ ] ;
117
- const isFileOrDir = revision && [
117
+ const isFileOrDirectory = revision && [
118
118
'raw' ,
119
119
'tree' ,
120
120
'blob' ,
@@ -139,7 +139,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
139
139
return `@${ user } ${ search } ${ hash } ` ;
140
140
}
141
141
142
- if ( isFileOrDir ) {
142
+ if ( isFileOrDirectory ) {
143
143
const revisioned = joinValues (
144
144
[ joinValues ( [ repoUrl , revision ] , '@' ) , filePath ] ,
145
145
'/' ,
@@ -162,9 +162,9 @@ function shortenURL(href, currentUrl = 'https://github.com') {
162
162
return `${ partial } ${ search } ${ hash } (release)` ;
163
163
}
164
164
165
- if ( releaseTagExt ) {
165
+ if ( releaseTagExtension ) {
166
166
const partial = joinValues ( [ repoUrl , `<code>${ releaseTag } </code>` ] , '@' ) ;
167
- return `${ partial } ${ releaseTagExt } ${ search } ${ hash } ` ;
167
+ return `${ partial } ${ releaseTagExtension } ${ search } ${ hash } ` ;
168
168
}
169
169
170
170
if ( downloadFilename ) {
@@ -241,7 +241,7 @@ function shortenURL(href, currentUrl = 'https://github.com') {
241
241
return pathname . replaceAll ( / ^ [ / ] | [ / ] $ / g, '' ) + url . search + hash + query ;
242
242
}
243
243
244
- function applyToLink ( a , currentUrl ) {
244
+ export function applyToLink ( a , currentUrl ) {
245
245
// Shorten only if the link name hasn't been customized.
246
246
// .href automatically adds a / to naked origins so that needs to be tested too
247
247
// `trim` makes it compatible with this feature: https://github.com/sindresorhus/refined-github/pull/3085
@@ -250,13 +250,12 @@ function applyToLink(a, currentUrl) {
250
250
( url === a . textContent . trim ( ) || url === `${ a . textContent } /` )
251
251
&& ! a . firstElementChild
252
252
) {
253
- const shortened = shortenURL ( url , currentUrl ) ;
253
+ const shortened = shortenRepoUrl ( url , currentUrl ) ;
254
254
a . innerHTML = shortened ;
255
255
return true ;
256
256
}
257
257
258
258
return false ;
259
259
}
260
260
261
- module . exports = shortenURL ;
262
- module . exports . applyToLink = applyToLink ;
261
+ export default shortenRepoUrl ;
0 commit comments