Created
May 19, 2011 08:10
-
-
Save can3p/980382 to your computer and use it in GitHub Desktop.
url parsing on coffeescript
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
parseUrl = ( url = location.href ) -> | |
params = {} | |
( ( parts = part.split( "=" ) ) && params[ parts[0] ] = parts[1] for part in ( url.split "?" ).pop().split "&" if url.indexOf( "?" ) != -1 ) && params || {} | |
$ -> | |
console.log parseUrl( "http://test.com/?a=b" ) | |
console.log parseUrl( "http://test.com" ) | |
console.log parseUrl() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment