Skip to content

Instantly share code, notes, and snippets.

@davidthingsaker
Created October 8, 2013 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidthingsaker/6883026 to your computer and use it in GitHub Desktop.
Save davidthingsaker/6883026 to your computer and use it in GitHub Desktop.
A coffee script function to parse and update a query string in Javascript. Modified from code found on stack overflow.
parseQS: (qs, key, value) =>
re = new RegExp("([?&])" + key + "=.*?(&|$)","i");
separator = qs.indexOf('?') != -1 ? "&" : "?";
console.log separator
if qs.match(re)
return qs.replace(re, '$1' + key + "=" + value + '$2');
else
return qs + key + "=" + value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment