Skip to content

Latest commit

 

History

History
103 lines (58 loc) · 1.61 KB

File metadata and controls

103 lines (58 loc) · 1.61 KB

Class: DynamicURL

Constructors

Constructor

new DynamicURL(url): DynamicURL

Parameters

url

string

Returns

DynamicURL

Methods

resolve()

resolve(): string

Resolves and returns the final URL as a string.

Returns

string

Example

const url = new DynamicURL("https://example.com/{citizen}/{hero}");
url.setRouteParams({ citizen: "robespierre", hero: "ironman" });

// Resolve the final URL
console.log(url.resolve()); // "https://example.com/robespierre/ironman"

setQueryParams()

setQueryParams(query, options?): DynamicURL

Takes a query object and appends it to the URL as a query string.

Parameters

query

Record<string, any>

An object representing the query parameters.

options?

IStringifyQueryOptions

Returns

DynamicURL

Example

const url = new DynamicURL("https://example.com");
url.setQueryParams({ citizen: "robespierre", hero: "ironman" });
console.log(url.resolve()); // "https://example.com?citizen=robespierre&hero=ironman"

setRouteParams()

setRouteParams(replaceValue): DynamicURL

Replaces route parameters in the URL with the provided values.

Parameters

replaceValue

An object or string to replace the route parameters.

string | TParamsObject

Returns

DynamicURL

See

TParamsObject

Example

const url = new DynamicURL("https://example.com/{citizen}/{hero}");
url.setRouteParams({ citizen: "robespierre", hero: "ironman" });
console.log(url.resolve()); // "https://example.com/robespierre/ironman"