1
+ import { Library , Query } from '~/types' ;
2
+
1
3
import { getNewArchSupportStatus , NewArchSupportStatus } from './newArchStatus' ;
2
4
import { relevance } from './sorting' ;
3
5
import { isEmptyOrNull } from './strings' ;
4
- import { Library , Query } from '../types' ;
6
+
7
+ const NPM_NAME_CLEANUP_REGEX = / [ - / ] / g;
8
+ const GITHUB_URL_CLEANUP_REGEX =
9
+ / ^ h t t p s ? : \/ \/ (?: w w w \. ) ? g i t h u b \. c o m \/ ( [ ^ / ] + \/ [ ^ / ] + ) (?: $ | \/ | \. g i t ) .* $ / ;
5
10
6
11
function calculateMatchScore (
7
- { github, npmPkg, topicSearchString, unmaintained } : Library ,
12
+ { github, npmPkg, topicSearchString, unmaintained, githubUrl } : Library ,
8
13
querySearch : string
9
14
) {
10
15
const exactNameMatchPoints =
@@ -15,10 +20,17 @@ function calculateMatchScore(
15
20
16
21
const npmPkgNameMatchPoints =
17
22
! isEmptyOrNull ( npmPkg ) &&
18
- ( npmPkg . includes ( querySearch ) || npmPkg . replaceAll ( / [ - / ] / g, ' ' ) . includes ( querySearch ) )
23
+ ( npmPkg . includes ( querySearch ) ||
24
+ npmPkg . replaceAll ( NPM_NAME_CLEANUP_REGEX , ' ' ) . includes ( querySearch ) )
19
25
? 200
20
26
: 0 ;
21
27
28
+ const gitHubURLOrOwnerMatchPoints =
29
+ githubUrl . startsWith ( querySearch ) ||
30
+ githubUrl . replace ( GITHUB_URL_CLEANUP_REGEX , '$1' ) . includes ( querySearch )
31
+ ? 150
32
+ : 0 ;
33
+
22
34
const cleanedUpName = npmPkg
23
35
. replace ( 'react-native' , '' )
24
36
. replace ( 'react' , '' )
@@ -28,7 +40,7 @@ function calculateMatchScore(
28
40
const cleanedUpNameMatchPoints =
29
41
! isEmptyOrNull ( cleanedUpName ) &&
30
42
( cleanedUpName . includes ( querySearch ) ||
31
- cleanedUpName . includes ( querySearch . replaceAll ( / [ - / ] / g , ' ' ) ) )
43
+ cleanedUpName . includes ( querySearch . replaceAll ( NPM_NAME_CLEANUP_REGEX , ' ' ) ) )
32
44
? 100
33
45
: 0 ;
34
46
@@ -47,6 +59,7 @@ function calculateMatchScore(
47
59
repoNameMatchPoints +
48
60
cleanedUpNameMatchPoints +
49
61
npmPkgNameMatchPoints +
62
+ gitHubURLOrOwnerMatchPoints +
50
63
descriptionMatchPoints +
51
64
topicMatchPoints ;
52
65
@@ -90,7 +103,7 @@ export function handleFilterLibraries({
90
103
} ) )
91
104
: libraries ;
92
105
93
- const fiteredLibraries = processedLibraries . filter ( library => {
106
+ const filteredLibraries = processedLibraries . filter ( library => {
94
107
let isTopicMatch = false ;
95
108
let isSearchMatch = false ;
96
109
@@ -236,10 +249,10 @@ export function handleFilterLibraries({
236
249
} ) ;
237
250
238
251
if ( sortBy === 'relevance' ) {
239
- return relevance ( fiteredLibraries ) ;
252
+ return relevance ( filteredLibraries ) ;
240
253
}
241
254
242
- return fiteredLibraries ;
255
+ return filteredLibraries ;
243
256
}
244
257
245
258
export function getPageQuery ( basePath : string , query : Query ) {
0 commit comments