forked from cube-js/cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseHref.ts
More file actions
21 lines (19 loc) · 703 Bytes
/
parseHref.ts
File metadata and controls
21 lines (19 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default function parseHref(href: string, titleSuffixCount: number): parseHref {
const stringWithOutGitHubSlug = href.replace('https://github.com/', '');
const arrayOfStringData = stringWithOutGitHubSlug.split('/');
const user = arrayOfStringData?.[0] || null;
const repo = arrayOfStringData?.[1] || null;
const branch = arrayOfStringData?.[3] || null;
const title =
[...arrayOfStringData]
?.reverse()
?.splice(0, titleSuffixCount)
?.reverse()
?.join('/') || '';
const filePath = arrayOfStringData?.splice(4)?.join('/') || null;
return { user, repo, branch, filePath, title };
}
interface parseHref {
[key: string]: string | null;
title: string;
}