Skip to content

Commit ba93d24

Browse files
committed
feat: rewrite utils to typescript
1 parent 1ae13a3 commit ba93d24

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/utils.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { posix as path } from 'path'
2+
import { NuxtOptions } from '@nuxt/types'
3+
4+
export function joinUrl (...args: string[]) {
5+
return path.join(...args).replace(':/', '://')
6+
}
7+
8+
export function isUrl (url: string) {
9+
return url.indexOf('http') === 0 || url.indexOf('//') === 0
10+
}
11+
12+
export function getRouteParams (options: NuxtOptions) {
13+
// routerBase
14+
const routerBase = options.router.base
15+
16+
// publicPath
17+
let publicPath
18+
if (isUrl(options.build.publicPath)) {
19+
publicPath = options.build.publicPath
20+
} else {
21+
publicPath = joinUrl(routerBase, options.build.publicPath)
22+
}
23+
24+
return {
25+
routerBase,
26+
publicPath
27+
}
28+
}
29+
30+
module.exports = {
31+
joinUrl,
32+
getRouteParams
33+
}

0 commit comments

Comments
 (0)