UNPKG

628 BJavaScriptView Raw
1export function getGitHubRepoSlug(pkg) {
2 let match = null;
3 if (typeof pkg.repository === 'string') {
4 match = pkg.repository.match(/^(?:github:)?([^/:]+\/[^/:]+)$/);
5 }
6 else {
7 let url = null;
8 if (pkg.repository && typeof pkg.repository.url === 'string') {
9 url = pkg.repository && pkg.repository.url;
10 }
11 else if (typeof pkg.homepage === 'string') {
12 url = pkg.homepage;
13 }
14 else {
15 return null;
16 }
17 match = url.match(/github\.com\/([^/:]+\/[^/:]+?)(?:\.git|\/)?$/);
18 }
19 return (match && match[1]) || null;
20}