API reference docs for QueryString

This commit is contained in:
Steve Gravrock
2025-09-17 20:16:16 -07:00
parent 418e9a7728
commit 124effe04b
2 changed files with 50 additions and 0 deletions

View File

@@ -1,11 +1,24 @@
jasmineRequire.QueryString = function() {
/**
* Reads and manipulates the query string.
* @since 2.0.0
*/
class QueryString {
#getWindowLocation;
/**
* @param options Object with a getWindowLocation property, which should be
* a function returning the current value of window.location.
*/
constructor(options) {
this.#getWindowLocation = options.getWindowLocation;
}
/**
* Sets the specified query parameter and navigates to the resulting URL.
* @param {string} key
* @param {string} value
*/
navigateWithNewParam(key, value) {
this.#getWindowLocation().search = this.fullStringWithNewParam(
key,
@@ -13,12 +26,24 @@ jasmineRequire.QueryString = function() {
);
}
/**
* Returns a new URL based on the current location, with the specified
* query parameter set.
* @param {string} key
* @param {string} value
* @return {string}
*/
fullStringWithNewParam(key, value) {
const paramMap = this.#queryStringToParamMap();
paramMap[key] = value;
return toQueryString(paramMap);
}
/**
* Gets the value of the specified query parameter.
* @param {string} key
* @return {string}
*/
getParam(key) {
return this.#queryStringToParamMap()[key];
}