Kind: Function
Source: src/utils/url.ts
Part of: Utils
Merge paths.
mergePath combines path values into a single URL path. Use it when building route, endpoint, or asset paths so callers do not need to concatenate path strings manually.
Signature
tsfunction mergePath(base: string | undefined, sub: string | undefined, rest: string[]): string
Parameters
| Name | Type |
|---|---|
base | `string |
sub | `string |
rest | string[] |
Returns: string
Diagram
mermaidgraph LR A[Base path] --> C[mergePath] B[Path segment] --> C C --> D[Merged path]
Usage
tsimport { mergePath } from './utils/url';
const usersPath = mergePath('/api/', '/users');
console.log(usersPath); // /api/users
AI Coding Instructions
- Pass path segments to
mergePathinstead of concatenating strings with/. - Keep path inputs consistent with existing callers, especially leading and trailing slashes.
- Use this helper when constructing routes, API endpoints, or asset paths in shared URL-building code.
- Do not assume it handles full URLs, query parameters, or hash fragments unless its implementation supports them.
Used by
1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (1)
HonoOptions—src/hono-base.ts:46
Was this page helpful?