UNPKG

412 BJavaScriptView Raw
1module.exports = (repositoryUrl) => {
2 const [match, auth, host, path] = /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<path>.*)$/.exec(repositoryUrl) || [];
3 try {
4 const [, owner, repo] = /^\/(?<owner>[^/]+)?\/?(?<repo>.+?)(?:\.git)?$/.exec(
5 new URL(match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl).pathname
6 );
7 return {owner, repo};
8 } catch {
9 return {};
10 }
11};