Integrations.utils.ts31 lines · main
1/**
2 * Builds the integrations page key from pathname segments.
3 * e.g. /project/ref/integrations → 'integrations'
4 * /project/ref/integrations/abc-123 → 'integrations/abc-123'
5 * Returns empty string if path is too short.
6 */
7export function getIntegrationsPageFromPathname(pathname: string): string {
8 const segments = pathname.split('/').filter(Boolean)
9 const projectIndex = segments.indexOf('project')
10 if (projectIndex === -1 || segments.length <= projectIndex + 2) return ''
11
12 const section = segments[projectIndex + 2]
13 const subSection = segments[projectIndex + 3]
14 if (!section) return ''
15
16 return subSection ? `${section}/${subSection}` : section
17}
18
19/**
20 * Extracts the 'category' query parameter from a full URL (asPath).
21 * Returns null if not present or asPath is invalid.
22 */
23export function getCategoryParamFromAsPath(asPath: string | undefined): string | null {
24 if (!asPath || typeof asPath !== 'string') return null
25
26 const queryPart = asPath.split('?')[1]
27 if (!queryPart) return null
28
29 const params = new URLSearchParams(queryPart)
30 return params.get('category')
31}