MCPcopy Create free account
hub / github.com/ampproject/amphtml / parseQueryString

Function parseQueryString

third_party/subscriptions-project/swg-gaa.js:864–884  ·  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

862 * @return {!Object<string, string>}
863 */
864function parseQueryString(query) {
865 if (!query) {
866 return {};
867 }
868 return (/^[?#]/.test(query) ? query.slice(1) : query)
869 .split('&')
870 .reduce((params, param) => {
871 const item = param.split('=');
872 try {
873 const key = decodeURIComponent(item[0] || '');
874 const value = decodeURIComponent(item[1] || '');
875 if (key) {
876 params[key] = value;
877 }
878 } catch (err) {
879 // eslint-disable-next-line no-console
880 warn(`SwG could not parse a URL query param: ${item[0]}`);
881 }
882 return params;
883 }, {});
884}
885
886/**
887 * Adds a parameter to a query string.

Callers 3

showMethod · 0.70
showMethod · 0.70

Calls 2

warnFunction · 0.70
testMethod · 0.45

Tested by

no test coverage detected