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

Function parseKeyValue

test/angular/1.5/angular.js:1420–1445  ·  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

1418 * @returns {Object.<string,boolean|Array>}
1419 */
1420function parseKeyValue(/**string*/keyValue) {
1421 var obj = {};
1422 forEach((keyValue || '').split('&'), function(keyValue) {
1423 var splitPoint, key, val;
1424 if (keyValue) {
1425 key = keyValue = keyValue.replace(/\+/g,'%20');
1426 splitPoint = keyValue.indexOf('=');
1427 if (splitPoint !== -1) {
1428 key = keyValue.substring(0, splitPoint);
1429 val = keyValue.substring(splitPoint + 1);
1430 }
1431 key = tryDecodeURIComponent(key);
1432 if (isDefined(key)) {
1433 val = isDefined(val) ? tryDecodeURIComponent(val) : true;
1434 if (!hasOwnProperty.call(obj, key)) {
1435 obj[key] = val;
1436 } else if (isArray(obj[key])) {
1437 obj[key].push(val);
1438 } else {
1439 obj[key] = [obj[key],val];
1440 }
1441 }
1442 }
1443 });
1444 return obj;
1445}
1446
1447function toKeyValue(obj) {
1448 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