Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
js :: url query parameter utilities
var getQueryParamsAsObject = function (qparamList) {
var qparams = {}, pairs;
if (qparamList) {
pairs = $.map(qparamList.split('&'), function (v) {
var pair = {}, keyVal = v.split('=');
pair[keyVal[0]] = keyVal[1];
return pair;
});
$.each(pairs, function (i, v) {
$.extend(qparams, v);
});
}
return qparams;
};
var toQueryParamList = function (qparamObj) {
var pairs = [];
for(var i in qparamObj) {
if (qparamObj.hasOwnProperty(i)) {
pairs.push(i + '=' + qparamObj[i]);
}
}
return pairs.join('&');
};
var updateQueryParam = function (qparamList, key, val) {
var qparamObj = getQueryParamsAsObject(qparamList);
if (val) {
qparamObj[key] = val;
} else { // deletes key if no val is sent
delete qparamObj[key];
}
return toQueryParamList(qparamObj);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.