Created
July 22, 2015 17:04
-
-
Save KOBA789/d0a9ac807ea751bfb8fc to your computer and use it in GitHub Desktop.
QueryString Parser/Stringifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS CODE IS LICENCED UNDER WTFPL | |
var qs = { | |
get: function () { | |
return qs.parse(window.location.search.substring(1)); | |
}, | |
parse: function (str) { | |
return str.split('&').map(function (value) { return value.split('='); }) | |
.reduce(function (obj, pair) { | |
obj[pair[0]] = decodeURIComponent(pair[1]); | |
return obj; | |
}, {}); | |
}, | |
stringify: function (obj) { | |
return Object.keys(obj).map(function (key) { | |
return [key, encodeURIComponent(obj[key])].join('='); | |
}).join('&'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment