Uri class

Class that represents a Uri and allows parsing/getting and setting of individual parts

Constructors

Uri(string, IUriParseOptions)

Create a new Uri.

Properties

absoluteUri

Set the absolute uri string for this Uri. Replaces all existing values

hashString

The hash string of the uri

host

The uri hostname (does not include port or scheme)

noSchemeSeparator

If true, do not emit the "//" separator after the scheme: Set to true for schemes like mailto (e.g. mailto:foo@bar)

path

The relative path of the uri

port

The port number of the uri as supplied in the url. 0 if left out in the url (e.g. the default port for the scheme).

queryParameters

The array of query parameters in the uri

queryString

Set the query string for this Uri. Replaces existing value

scheme

The uri scheme such as http or https

Methods

addQueryParam(string, null | string, boolean)

Adds a query string parameter to the current uri

addQueryParams({[key: string]: QueryParameterValueType}, boolean, string)

Adds query string parameters to the current uri

getEffectivePort()

Gets the effective port number, returning the default port number if omitted for the given scheme.

getQueryParam(string)

Get the value of the query parameter with the given key

removeQueryParam(string)

Removes a query string parameter

Constructor Details

Uri(string, IUriParseOptions)

Create a new Uri.

new Uri(uri?: string, options?: IUriParseOptions)

Parameters

uri

string

Optional uri string to populate values with

options
IUriParseOptions

Options for parsing the uri string

Property Details

absoluteUri

Set the absolute uri string for this Uri. Replaces all existing values

absoluteUri: string

Property Value

string

hashString

The hash string of the uri

hashString: string

Property Value

string

host

The uri hostname (does not include port or scheme)

host: string

Property Value

string

noSchemeSeparator

If true, do not emit the "//" separator after the scheme: Set to true for schemes like mailto (e.g. mailto:foo@bar)

noSchemeSeparator: boolean

Property Value

boolean

path

The relative path of the uri

path: string

Property Value

string

port

The port number of the uri as supplied in the url. 0 if left out in the url (e.g. the default port for the scheme).

port: number

Property Value

number

queryParameters

The array of query parameters in the uri

queryParameters: IQueryParameter[]

Property Value

queryString

Set the query string for this Uri. Replaces existing value

queryString: string

Property Value

string

scheme

The uri scheme such as http or https

scheme: string

Property Value

string

Method Details

addQueryParam(string, null | string, boolean)

Adds a query string parameter to the current uri

function addQueryParam(name: string, value: null | string, replaceExisting?: boolean)

Parameters

name

string

The Query parameter name

value

null | string

The Query parameter value

replaceExisting

boolean

If true, replace all existing parameters with the same name

addQueryParams({[key: string]: QueryParameterValueType}, boolean, string)

Adds query string parameters to the current uri

function addQueryParams(parameters: {[key: string]: QueryParameterValueType}, replaceExisting?: boolean, keyPrefix?: string)

Parameters

parameters

{[key: string]: QueryParameterValueType}

Query parameters to add

replaceExisting

boolean

If true, replace all existing parameters with the same name

keyPrefix

string

If specified, a value to prepend to all query parameter keys

getEffectivePort()

Gets the effective port number, returning the default port number if omitted for the given scheme.

function getEffectivePort(): number

Returns

number

getQueryParam(string)

Get the value of the query parameter with the given key

function getQueryParam(name: string): undefined | null | string

Parameters

name

string

Query parameter name

Returns

undefined | null | string

removeQueryParam(string)

Removes a query string parameter

function removeQueryParam(name: string)

Parameters

name

string

The Query parameter name