Convert QueryString to an ES6 class
This commit is contained in:
@@ -970,38 +970,32 @@ jasmineRequire.ResultsNode = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
jasmineRequire.QueryString = function() {
|
jasmineRequire.QueryString = function() {
|
||||||
function QueryString(options) {
|
class QueryString {
|
||||||
this.navigateWithNewParam = function(key, value) {
|
#getWindowLocation;
|
||||||
options.getWindowLocation().search = this.fullStringWithNewParam(
|
|
||||||
|
constructor(options) {
|
||||||
|
this.#getWindowLocation = options.getWindowLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
navigateWithNewParam(key, value) {
|
||||||
|
this.#getWindowLocation().search = this.fullStringWithNewParam(
|
||||||
key,
|
key,
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
this.fullStringWithNewParam = function(key, value) {
|
|
||||||
const paramMap = queryStringToParamMap();
|
|
||||||
paramMap[key] = value;
|
|
||||||
return toQueryString(paramMap);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getParam = function(key) {
|
|
||||||
return queryStringToParamMap()[key];
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
function toQueryString(paramMap) {
|
|
||||||
const qStrPairs = [];
|
|
||||||
for (const prop in paramMap) {
|
|
||||||
qStrPairs.push(
|
|
||||||
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return '?' + qStrPairs.join('&');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryStringToParamMap() {
|
fullStringWithNewParam(key, value) {
|
||||||
const paramStr = options.getWindowLocation().search.substring(1);
|
const paramMap = this.#queryStringToParamMap();
|
||||||
|
paramMap[key] = value;
|
||||||
|
return toQueryString(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
getParam(key) {
|
||||||
|
return this.#queryStringToParamMap()[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
#queryStringToParamMap() {
|
||||||
|
const paramStr = this.#getWindowLocation().search.substring(1);
|
||||||
let params = [];
|
let params = [];
|
||||||
const paramMap = {};
|
const paramMap = {};
|
||||||
|
|
||||||
@@ -1021,6 +1015,16 @@ jasmineRequire.QueryString = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toQueryString(paramMap) {
|
||||||
|
const qStrPairs = [];
|
||||||
|
for (const prop in paramMap) {
|
||||||
|
qStrPairs.push(
|
||||||
|
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return '?' + qStrPairs.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
return QueryString;
|
return QueryString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,30 @@
|
|||||||
jasmineRequire.QueryString = function() {
|
jasmineRequire.QueryString = function() {
|
||||||
function QueryString(options) {
|
class QueryString {
|
||||||
this.navigateWithNewParam = function(key, value) {
|
#getWindowLocation;
|
||||||
options.getWindowLocation().search = this.fullStringWithNewParam(
|
|
||||||
|
constructor(options) {
|
||||||
|
this.#getWindowLocation = options.getWindowLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
navigateWithNewParam(key, value) {
|
||||||
|
this.#getWindowLocation().search = this.fullStringWithNewParam(
|
||||||
key,
|
key,
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
this.fullStringWithNewParam = function(key, value) {
|
|
||||||
const paramMap = queryStringToParamMap();
|
|
||||||
paramMap[key] = value;
|
|
||||||
return toQueryString(paramMap);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getParam = function(key) {
|
|
||||||
return queryStringToParamMap()[key];
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
function toQueryString(paramMap) {
|
|
||||||
const qStrPairs = [];
|
|
||||||
for (const prop in paramMap) {
|
|
||||||
qStrPairs.push(
|
|
||||||
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return '?' + qStrPairs.join('&');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryStringToParamMap() {
|
fullStringWithNewParam(key, value) {
|
||||||
const paramStr = options.getWindowLocation().search.substring(1);
|
const paramMap = this.#queryStringToParamMap();
|
||||||
|
paramMap[key] = value;
|
||||||
|
return toQueryString(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
getParam(key) {
|
||||||
|
return this.#queryStringToParamMap()[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
#queryStringToParamMap() {
|
||||||
|
const paramStr = this.#getWindowLocation().search.substring(1);
|
||||||
let params = [];
|
let params = [];
|
||||||
const paramMap = {};
|
const paramMap = {};
|
||||||
|
|
||||||
@@ -50,5 +44,15 @@ jasmineRequire.QueryString = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toQueryString(paramMap) {
|
||||||
|
const qStrPairs = [];
|
||||||
|
for (const prop in paramMap) {
|
||||||
|
qStrPairs.push(
|
||||||
|
encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return '?' + qStrPairs.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
return QueryString;
|
return QueryString;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user