Skip to content
Myr

utils.ts

This file

Path

src/client/utils.ts

42 lines · 1.1 KiB · TypeScript

Last changed by

fix(client): Fix regex pattern with length limit at replaceUrlParam (#2193)Fukuibefore adoption13b5855

History of this file

Take it

The walk stopped after 200 commits: lines older than 2f9a07d point at it.

perf(hono-base): use `instanceOf` (#1565)Yusuke Wadabefore adoption2f9a07d

lines 1–11why, one step back
1import type { ObjectType } from './types'
23export const mergePath = (base: string, path: string) => {4 base = base.replace(/\/+$/, '')5 base = base + '/'6 path = path.replace(/^\/+/, '')7 return base + path8}910export const replaceUrlParam = (urlString: string, params: Record<string, string>) => {11 for (const [k, v] of Object.entries(params)) {

fix(client): Fix regex pattern with length limit at replaceUrlParam (#2193)Fukuibefore adoption13b5855

line 12why, one step back
12 const reg = new RegExp('/:' + k + '(?:{[^/]+})?')

perf(hono-base): use `instanceOf` (#1565)Yusuke Wadabefore adoption2f9a07d

lines 13–42why, one step back
13 urlString = urlString.replace(reg, `/${v}`)
14 }15 return urlString16}1718export const removeIndexString = (urlSting: string) => {19 return urlSting.replace(/\/index$/, '/')20}2122function isObject(item: unknown): item is ObjectType {23 return typeof item === 'object' && item !== null && !Array.isArray(item)24}2526export function deepMerge<T>(target: T, source: Record<string, unknown>): T {27 if (!isObject(target) && !isObject(source)) {28 return source as T29 }30 const merged = { ...target } as ObjectType<T>3132 for (const key in source) {33 const value = source[key]34 if (isObject(merged[key]) && isObject(value)) {35 merged[key] = deepMerge(merged[key], value)36 } else {37 merged[key] = value as T[keyof T] & T38 }39 }4041 return merged as T42}