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