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

Function parseKeyValue

test/angular/1.6/angular.js:1550–1575  ·  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

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