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

Function parseKeyValue

test/angular/1.7/angular.js:1547–1572  ·  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

1545 * @returns {Object.<string,boolean|Array>}
1546 */
1547function parseKeyValue(/**string*/keyValue) {
1548 var obj = {};
1549 forEach((keyValue || '').split('&'), function(keyValue) {
1550 var splitPoint, key, val;
1551 if (keyValue) {
1552 key = keyValue = keyValue.replace(/\+/g,'%20');
1553 splitPoint = keyValue.indexOf('=');
1554 if (splitPoint !== -1) {
1555 key = keyValue.substring(0, splitPoint);
1556 val = keyValue.substring(splitPoint + 1);
1557 }
1558 key = tryDecodeURIComponent(key);
1559 if (isDefined(key)) {
1560 val = isDefined(val) ? tryDecodeURIComponent(val) : true;
1561 if (!hasOwnProperty.call(obj, key)) {
1562 obj[key] = val;
1563 } else if (isArray(obj[key])) {
1564 obj[key].push(val);
1565 } else {
1566 obj[key] = [obj[key],val];
1567 }
1568 }
1569 }
1570 });
1571 return obj;
1572}
1573
1574function toKeyValue(obj) {
1575 var parts = [];

Callers 3

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