MCPcopy Create free account
hub / github.com/aosabook/500lines / parseKeyValue

Function parseKeyValue

spreadsheet/code/lib/angular.js:1155–1174  ·  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

1153 * @returns {Object.<string,boolean|Array>}
1154 */
1155function parseKeyValue(/**string*/keyValue) {
1156 var obj = {}, key_value, key;
1157 forEach((keyValue || "").split('&'), function(keyValue) {
1158 if ( keyValue ) {
1159 key_value = keyValue.replace(/\+/g,'%20').split('=');
1160 key = tryDecodeURIComponent(key_value[0]);
1161 if ( isDefined(key) ) {
1162 var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
1163 if (!hasOwnProperty.call(obj, key)) {
1164 obj[key] = val;
1165 } else if(isArray(obj[key])) {
1166 obj[key].push(val);
1167 } else {
1168 obj[key] = [obj[key],val];
1169 }
1170 }
1171 }
1172 });
1173 return obj;
1174}
1175
1176function toKeyValue(obj) {
1177 var parts = [];

Callers 2

parseAppUrlFunction · 0.85
angular.jsFile · 0.85

Calls 4

forEachFunction · 0.85
tryDecodeURIComponentFunction · 0.85
isDefinedFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected