-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
49 lines (47 loc) · 1.05 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
export function compareWithUndefined(a, b) {
if (a === b) {
return 0;
}
if (a === undefined) {
return -1;
}
if (b === undefined) {
return 1;
}
return a - b;
}
export function applyConfig(packages, config) {
return packages
.filter((pkg) => {
let keep = true;
for (const excludeRule of config.excludeRules) {
if (excludeRule.shouldExcludePackage(pkg)) {
console.error(
`ignoring package "${pkg.name}" because of "${excludeRule.reason}"`
);
keep = false;
break;
}
}
return keep;
})
.sort(
(a, b) =>
-1 *
compareWithUndefined(a?.gitHubStargazersCount, b?.gitHubStargazersCount)
);
}
export function getGitHubSlug(pkg) {
if (pkg.gitHubLink === undefined) {
return undefined;
}
try {
const url = new URL(pkg.gitHubLink);
if (url.hostname === "github.com") {
const slug = url.pathname.replace(/^\//, "").replace(/\.git$/, "");
return slug;
}
} catch (_) {
return undefined;
}
}