File size: 660 Bytes
a0040c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function isGitHubUrl(urlString: string): boolean {
  try {
    const url = new URL(urlString);
    const githubDomains = ['github.com', 'www.github.com'];
    return githubDomains.includes(url.hostname) && url.protocol === 'https:';
  } catch {
    return false;
  }
}

export function isGithubUserPath(url: string, username: string): boolean {
  if (!isGitHubUrl(url)) {
    return false;
  }
  const urlObject = new URL(url);
  const pathSegments = urlObject.pathname.split('/').filter((segment) => segment !== '');
  if (pathSegments.length === 0) {
    return false;
  }
  const pathUsername = pathSegments[0];
  return pathUsername === username;
}