* Parses an escaped url query string into key-value pairs. Logic taken from * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1382
(keyValue: string)
| 258 | * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1382 |
| 259 | */ |
| 260 | function parseKeyValue(keyValue: string): {[k: string]: unknown} { |
| 261 | const obj: {[k: string]: unknown} = {}; |
| 262 | (keyValue || '').split('&').forEach((keyValue) => { |
| 263 | let splitPoint, key, val; |
| 264 | if (keyValue) { |
| 265 | key = keyValue = keyValue.replace(/\+/g, '%20'); |
| 266 | splitPoint = keyValue.indexOf('='); |
| 267 | if (splitPoint !== -1) { |
| 268 | key = keyValue.substring(0, splitPoint); |
| 269 | val = keyValue.substring(splitPoint + 1); |
| 270 | } |
| 271 | key = tryDecodeURIComponent(key); |
| 272 | if (typeof key !== 'undefined') { |
| 273 | val = typeof val !== 'undefined' ? tryDecodeURIComponent(val) : true; |
| 274 | if (!obj.hasOwnProperty(key)) { |
| 275 | obj[key] = val; |
| 276 | } else if (Array.isArray(obj[key])) { |
| 277 | (obj[key] as unknown[]).push(val); |
| 278 | } else { |
| 279 | obj[key] = [obj[key], val]; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | }); |
| 284 | return obj; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Serializes into key-value pairs. Logic taken from |