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
.
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
).
Note: To simplify a future migration from this class to the standard URLSearchParams
API, consuming code should follow some recommendations:
location.search
).get
method with the second parameter bAll
; use the getAll
method insteadmParams
(you never should access internal properties of UI5 classes or objects). With the predecessor of this API, access to mParams
was often used to check whether a parameter is defined at all. Using the new has
method or checking the result of get
against null
serves the same purpose.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.Method | Description |
---|---|
module:sap/base/util/UriParameters.fromQuery |
Parses the given query string and returns an interface to access the individual parameters. Callers using |
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 |
get |
Returns the first value of the named query parameter. The value of the first occurrence of the parameter with name If (and only if) the parameter does not occur in the query string, |
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. |
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 |
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. |
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 |
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 |