class sap/base/util/UriParameters

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Extends:
Module: sap/base/util/UriParameters
Application Component:

Provides access to the individual parameters of a URL query string.

This class parses the query string from a URL and provides access to the values of individual parameters. There are methods to check whether the query string contains a parameter (has()), to get a single value (get()) for a parameter and to get a list of all values (getAll()) for a parameter. Another method allows to iterate over all parameter names (keys()).

The signature and behavior of those methods is aligned with the corresponding methods of the upcoming Web API URLSearchParams.

Decoding

The constructor and the factory methods expect percentage encoded input whereas all other APIs expect and return decoded strings. After parsing the query string, any plus sign (0x2b) in names or values is replaced by a blank (0x20) and the resulting strings are percentage decoded (decodeURIComponent).

Future Migration

Note: To simplify a future migration from this class to the standard URLSearchParams API, consuming code should follow some recommendations:

Callers using UriParameters.fromQuery(input) can be migrated to new URLSearchParams(input) once the new API is available in all supported browsers. Callers using UriParameters.fromURL(input) can be migrated to new URL(input).searchParams then.

Documentation links:


Constructor

new module:sap/base/util/UriParameters(sURL?)
Param Type Default Value Description
sURL? string

URL with parameters


Methods Overview

Method Description
module:sap/base/util/UriParameters.fromQuery

Parses the given query string and returns an interface to access the individual parameters.

Callers using UriParameters.fromQuery(input) can be migrated to new URLSearchParams(input) once that API is available (or polyfilled) in all supported browsers.

module:sap/base/util/UriParameters.fromURL

Parses the query portion of the given URL and returns an object to access the individual parameters.

Callers using UriParameters.fromURL(input) can be migrated to new URL(input).searchParams once that API is available (or polyfilled) in all supported browsers.

get

Returns the first value of the named query parameter.

The value of the first occurrence of the parameter with name sName in the query string is returned. If that first occurrence does not contain a value (it does not contain an equal sign), then an empty string is returned.

If (and only if) the parameter does not occur in the query string, null is returned.

getAll

Returns all values of the query parameter with the given name.

An array of string values of all occurrences of the parameter with the given name is returned. This array is empty if (and only if) the parameter does not occur in the query string.

has

Checks whether a parameter occurs at least once in the query string.

keys

Returns an iterator for all contained parameter names.

module:sap/base/util/UriParameters.fromQuery

Parses the given query string and returns an interface to access the individual parameters.

Callers using UriParameters.fromQuery(input) can be migrated to new URLSearchParams(input) once that API is available (or polyfilled) in all supported browsers.

Param Type DefaultValue Description
sQuery string ""

Query string to parse, a leading question mark (?) will be ignored

module:sap/base/util/UriParameters.fromURL

Parses the query portion of the given URL and returns an object to access the individual parameters.

Callers using UriParameters.fromURL(input) can be migrated to new URL(input).searchParams once that API is available (or polyfilled) in all supported browsers.

Param Type DefaultValue Description
sURL string

to parse the query portion of.

get

Returns the first value of the named query parameter.

The value of the first occurrence of the parameter with name sName in the query string is returned. If that first occurrence does not contain a value (it does not contain an equal sign), then an empty string is returned.

If (and only if) the parameter does not occur in the query string, null is returned.

Param Type DefaultValue Description
sName string

Name of the query parameter to get the value for

bAll boolean false

Whether all values for the parameter should be returned; the use of this parameter is deprecated and highly discouraged; use the #getAll method instead

getAll

Returns all values of the query parameter with the given name.

An array of string values of all occurrences of the parameter with the given name is returned. This array is empty if (and only if) the parameter does not occur in the query string.

Param Type DefaultValue Description
sName string

Name of the query parameter

has

Checks whether a parameter occurs at least once in the query string.

Param Type DefaultValue Description
sName string

Name of the query parameter to check

keys

Returns an iterator for all contained parameter names.