Skip to content

mergePath

reference
1 min readUpdated

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

ts
function mergePath(base: string | undefined, sub: string | undefined, rest: string[]): string

Parameters

NameType
base`string
sub`string
reststring[]

Returns: string

Diagram

mermaid
graph LR
  A[Base path] --> C[mergePath]
  B[Path segment] --> C
  C --> D[Merged path]

Usage

ts
import { mergePath } from './utils/url';

const usersPath = mergePath('/api/', '/users');

console.log(usersPath); // /api/users

AI Coding Instructions

  • Pass path segments to mergePath instead 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)

  • HonoOptionssrc/hono-base.ts:46

Was this page helpful?

Download as PDF
mergePath — Hono (narrator proof)