Skip to content

Instantly share code, notes, and snippets.

@davidthingsaker
davidthingsaker / parseQS
Created October 8, 2013 11:03
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;