MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / parseKeyValue

Function parseKeyValue

web/static/bower_components/angular/angular.js:1323–1348  ·  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

1321 * @returns {Object.<string,boolean|Array>}
1322 */
1323function parseKeyValue(/**string*/keyValue) {
1324 var obj = {};
1325 forEach((keyValue || "").split('&'), function(keyValue) {
1326 var splitPoint, key, val;
1327 if (keyValue) {
1328 key = keyValue = keyValue.replace(/\+/g,'%20');
1329 splitPoint = keyValue.indexOf('=');
1330 if (splitPoint !== -1) {
1331 key = keyValue.substring(0, splitPoint);
1332 val = keyValue.substring(splitPoint + 1);
1333 }
1334 key = tryDecodeURIComponent(key);
1335 if (isDefined(key)) {
1336 val = isDefined(val) ? tryDecodeURIComponent(val) : true;
1337 if (!hasOwnProperty.call(obj, key)) {
1338 obj[key] = val;
1339 } else if (isArray(obj[key])) {
1340 obj[key].push(val);
1341 } else {
1342 obj[key] = [obj[key],val];
1343 }
1344 }
1345 }
1346 });
1347 return obj;
1348}
1349
1350function toKeyValue(obj) {
1351 var parts = [];

Callers 2

parseAppUrlFunction · 0.85
angular.jsFile · 0.85

Calls 3

forEachFunction · 0.85
tryDecodeURIComponentFunction · 0.85
isDefinedFunction · 0.85

Tested by

no test coverage detected