0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 10:51:01 +00:00
hono/deno_dist/client/utils.ts

26 lines
723 B
TypeScript
Raw Normal View History

2023-02-07 22:22:32 +00:00
import { getPathFromURL } from '../utils/url.ts'
export const mergePath = (base: string, path: string) => {
base = base.replace(/\/+$/, '')
base = base + '/'
path = path.replace(/^\/+/, '')
return base + path
}
export const replaceUrlParam = (urlString: string, params: Record<string, string>) => {
for (const [k, v] of Object.entries(params)) {
const reg = new RegExp('/:' + k)
urlString = urlString.replace(reg, `/${v}`)
}
return urlString
}
export const removeIndexString = (urlSting: string) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const path = getPathFromURL(urlSting)
2023-02-07 22:22:32 +00:00
if (path === '/index') {
return urlSting.replace(/index$/, '')
}
return urlSting
}