MCPcopy
hub / github.com/angular-ui/ui-router / parseKeyValue

Function parseKeyValue

test/angular/1.4/angular.js:1359–1384  ·  view source on GitHub ↗

* Parses an escaped url query string into key-value pairs. * @returns {Object. }

(/**string*/keyValue)

Source from the content-addressed store, hash-verified

1357 * @returns {Object.<string,boolean|Array>}
1358 */
1359function parseKeyValue(/**string*/keyValue) {
1360 var obj = {};
1361 forEach((keyValue || "").split('&'), function(keyValue) {
1362 var splitPoint, key, val;
1363 if (keyValue) {
1364 key = keyValue = keyValue.replace(/\+/g,'%20');
1365 splitPoint = keyValue.indexOf('=');
1366 if (splitPoint !== -1) {
1367 key = keyValue.substring(0, splitPoint);
1368 val = keyValue.substring(splitPoint + 1);
1369 }
1370 key = tryDecodeURIComponent(key);
1371 if (isDefined(key)) {
1372 val = isDefined(val) ? tryDecodeURIComponent(val) : true;
1373 if (!hasOwnProperty.call(obj, key)) {
1374 obj[key] = val;
1375 } else if (isArray(obj[key])) {
1376 obj[key].push(val);
1377 } else {
1378 obj[key] = [obj[key],val];
1379 }
1380 }
1381 }
1382 });
1383 return obj;
1384}
1385
1386function toKeyValue(obj) {
1387 var parts = [];

Callers 2

parseAppUrlFunction · 0.70
angular.jsFile · 0.70

Calls 4

isArrayFunction · 0.85
forEachFunction · 0.70
tryDecodeURIComponentFunction · 0.70
isDefinedFunction · 0.70

Tested by

no test coverage detected