* Parses and builds Object of URL query string. * @param {string} query The URL query string. * @return {!Object }
(query)
| 862 | * @return {!Object<string, string>} |
| 863 | */ |
| 864 | function 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. |
no test coverage detected