mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 10:51:01 +00:00
60c0903a1c
* fix(req): return type as `string | undefined` * denoify
26 lines
723 B
TypeScript
26 lines
723 B
TypeScript
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)
|
|
if (path === '/index') {
|
|
return urlSting.replace(/index$/, '')
|
|
}
|
|
return urlSting
|
|
}
|