>From time to other, I find myself needing to manipulate the
query-string of URLs in javascript. I have put together the following
function. Is this general enough to put into mk?

extendURL = function(url, parameters) {
  var parts = url.split(/\?/);
  var base = parts[0];
  var args = update(isUndefinedOrNull(parts[1]) ? {} :
parseQueryString(parts[1]), parameters);
  var args2 = {};
  for (key in args) {
    if (!isUndefinedOrNull(args[key])) {
      args2[key] = args[key];
    }
  }
  if (keys(args2).length == 0) {
    return base;
  }
  return base + "?" + queryString(args2);
}

assert("foobar?zim=cux&salla=bim" == extendURL("foobar?zim=cux",
{salla: "bim"}));
assert("foobar" == extendURL("foobar?zim=cux", {zim: null}));
assert("foobar?salla=bim" == extendURL("foobar?zim=cux", {zim: null,
salla: "bim"}));

-- 
troels

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to