MCPcopy Index your code
hub / github.com/angular/angular / parseKeyValue

Function parseKeyValue

packages/common/upgrade/src/params.ts:260–285  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

258 * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1382
259 */
260function 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

Callers 2

encodeSearchMethod · 0.85
decodeSearchMethod · 0.85

Calls 6

tryDecodeURIComponentFunction · 0.85
indexOfMethod · 0.80
isArrayMethod · 0.80
forEachMethod · 0.45
replaceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…