Bewerken

Delen via


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

Get the absolute uri string for this Uri

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

Get the query string for this Uri.

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

Get the absolute uri string for this Uri

string absoluteUri

Property Value

string

hashString

The hash string of the uri

public hashString: string = ""

Property Value

string

host

The uri hostname (does not include port or scheme)

public 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)

public noSchemeSeparator: boolean = false

Property Value

boolean

path

The relative path of the uri

public 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).

public port: number = 0

Property Value

number

queryParameters

The array of query parameters in the uri

public queryParameters: IQueryParameter[] = []

Property Value

queryString

Get the query string for this Uri.

string queryString

Property Value

string

scheme

The uri scheme such as http or https

public 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