Skip to content

Function: buildUrl()

ts
function buildUrl(
   base, 
   path?, 
   query?): string;

Builds a URL from a base URL, path, and optional query object.

Parameters

ParameterTypeDefault valueDescription
basestringundefinedThe base URL.
pathstring''The path to append.
queryRecord<string, string | number>{}The query object.

Returns

string

The built URL string.

Example

ts
buildUrl('https://api.com', '/users', { page: 1 })
// => 'https://api.com/users?page=1'

Since

1.0.0

Released under the MIT License.