Skip to content

Instantly share code, notes, and snippets.

View ecabuk's full-sized avatar
🐣

Evrim ecabuk

🐣
View GitHub Profile
@ecabuk
ecabuk / pQuery.coffee
Last active February 6, 2016 00:52 — forked from niyazpk/pQuery.js
Add or update query string parameter
### Add / Update a key-value pair in the URL query parameters ###
updateUrlParameter = (uri, key, value)->
# Remove the hash part before operating on the uri
i = uri.indexOf('#')
hash = if i == -1 then '' else uri.substr(i)
uri = if i == -1 then uri else uri.substr(0, i)
re = new RegExp("([?&])" + key + "=.*?(&|$)", "i")
separator = if uri.indexOf('?') != -1 then "&" else "?"
if uri.match(re)