MCPcopy Index your code
hub / github.com/ampproject/amphtml / parseQueryString

Function parseQueryString

third_party/subscriptions-project/swg.js:5359–5379  ·  view source on GitHub ↗

* Parses and builds Object of URL query string. * @param {string} query The URL query string. * @return {!Object }

(query)

Source from the content-addressed store, hash-verified

5357 * @return {!Object<string, string>}
5358 */
5359function parseQueryString(query) {
5360 if (!query) {
5361 return {};
5362 }
5363 return (/^[?#]/.test(query) ? query.slice(1) : query)
5364 .split('&')
5365 .reduce((params, param) => {
5366 const item = param.split('=');
5367 try {
5368 const key = decodeURIComponent(item[0] || '');
5369 const value = decodeURIComponent(item[1] || '');
5370 if (key) {
5371 params[key] = value;
5372 }
5373 } catch (err) {
5374 // eslint-disable-next-line no-console
5375 warn(`SwG could not parse a URL query param: ${item[0]}`);
5376 }
5377 return params;
5378 }, {});
5379}
5380
5381/**
5382 * Adds a parameter to a query string.

Callers 8

getSwgModeFunction · 0.70
serviceUrlFunction · 0.70
feUrlFunction · 0.70
getExperimentsFunction · 0.70
setStaticContext_Method · 0.70
getGaaToken_Method · 0.70
addDevModeParamsToUrlFunction · 0.70

Calls 2

warnFunction · 0.70
testMethod · 0.45

Tested by

no test coverage detected