-
Notifications
You must be signed in to change notification settings - Fork 829
Expand file tree
/
Copy pathutils.ts
More file actions
25 lines (21 loc) · 865 Bytes
/
utils.ts
File metadata and controls
25 lines (21 loc) · 865 Bytes
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
import { type MarkdownTabsType } from '~/types';
export const MARKDOWN_CONTENT_QUERY_PARAM = 'tab';
export const MARKDOWN_TABS = ['Readme', 'Changelog', 'Contributing', 'Code of Conduct'] as const;
export const DEFAULT_MARKDOWN_TAB: MarkdownTabsType = 'Readme';
export function isValidMarkdownTab(
value?: string | string[],
availableTabs: readonly MarkdownTabsType[] = MARKDOWN_TABS
): value is MarkdownTabsType {
return typeof value === 'string' && availableTabs.includes(value as MarkdownTabsType);
}
export function parseMarkdownTab(
value?: string | string[],
availableTabs: readonly MarkdownTabsType[] = MARKDOWN_TABS
): MarkdownTabsType {
if (isValidMarkdownTab(value, availableTabs)) {
return value;
}
return availableTabs.includes(DEFAULT_MARKDOWN_TAB)
? DEFAULT_MARKDOWN_TAB
: (availableTabs[0] ?? DEFAULT_MARKDOWN_TAB);
}