Created
October 10, 2011 09:50
-
-
Save greystate/1274961 to your computer and use it in GitHub Desktop.
CoffeeScript QueryString class
This file contains hidden or 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
# Provide easy access to QueryString data | |
class QueryString | |
constructor: (@queryString) -> | |
@queryString or= window.document.location.search?.substr 1 | |
@variables = @queryString.split '&' | |
@pairs = ([key, value] = pair.split '=' for pair in @variables) | |
get: (name) -> | |
for [key, value] in @pairs | |
return value if key is name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All you need to do to address decoding is run both key and value through
decodeURIComponent
.