-
-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathrouter.ts
More file actions
67 lines (59 loc) · 1.51 KB
/
router.ts
File metadata and controls
67 lines (59 loc) · 1.51 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { RouteLocationRaw } from 'vue-router'
import { splitPackageName } from '~/utils/package-name'
export function packageRoute(
packageName: string,
version?: string | null,
hash?: string,
): RouteLocationRaw {
const { org, name } = splitPackageName(packageName)
if (version) {
return {
name: 'package-version',
params: {
org,
name,
// remove spaces to be correctly resolved by router
version: version.replace(/\s+/g, ''),
},
hash,
}
}
return {
name: 'package',
params: {
org,
name,
},
}
}
/** Full version history page (`/package/.../versions`) */
export function packageVersionsRoute(packageName: string): RouteLocationRaw {
const [org, name = ''] = packageName.startsWith('@') ? packageName.split('/') : ['', packageName]
return { name: 'package-versions', params: { org, name } }
}
export function diffRoute(
packageName: string,
fromVersion: string,
toVersion: string,
): RouteLocationRaw {
const { org, name } = splitPackageName(packageName)
return {
name: 'diff',
params: {
org: org || undefined,
packageName: name,
versionRange: `${fromVersion}...${toVersion}`,
},
}
}
export function packageTimelineRoute(packageName: string, version: string): RouteLocationRaw {
const { org, name } = splitPackageName(packageName)
return {
name: 'timeline',
params: {
org: org || undefined,
packageName: name,
version: version.replace(/\s+/g, ''),
},
}
}