Skip to main content
Module

x/urlcat/src/index.ts>default

A URL builder library for JavaScript.
Go to Latest
function default
import { default } from "https://deno.land/x/urlcat@v2.0.4/src/index.ts";

Builds a URL using the base template and specified parameters.

Examples

Example 1

urlcat('http://api.example.com/users/:id', { id: 42, search: 'foo' })
// -> 'http://api.example.com/users/42?search=foo

Parameters

baseTemplate: string

a URL template that contains zero or more :params

params: ParamMap

an object with properties that correspond to the :params in the base template. Unused properties become query params.

Returns

string

a URL with path params substituted and query params appended

Concatenates the base URL and the path specified using '/' as a separator. If a '/' occurs at the concatenation boundary in either parameter, it is removed.

Examples

Example 1

urlcat('http://api.example.com/', '/users')
// -> 'http://api.example.com/users

Parameters

baseUrl: string

the first part of the URL

path: string

the second part of the URL

Returns

string

the result of the concatenation

Concatenates the base URL and the path specified using '/' as a separator. If a '/' occurs at the concatenation boundary in either parameter, it is removed. Substitutes path parameters with the properties of the @see params object and appends unused properties in the path as query params.

Examples

Example 1

urlcat('http://api.example.com/', '/users/:id', { id: 42, search: 'foo' })
// -> 'http://api.example.com/users/42?search=foo

Parameters

baseUrl: string

the first part of the URL

pathTemplate: string

the second part of the URL

params: ParamMap

Object with properties that correspond to the :params in the base template. Unused properties become query params.

Returns

string

URL with path params substituted and query params appended