Forked from miohtama/parse-hash-bang-arguments-in-javascript.js
Last active
December 15, 2015 04:29
-
-
Save zaus/5201739 to your computer and use it in GitHub Desktop.
Parse "hashbang" `#!` arguments like url query-string. [original source](https://gist.github.com/miohtama/1570295)
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
/** | |
* Parse hash bang parameters from a URL as key value object. | |
* For repeated parameters the last parameter is effective. | |
* If = syntax is not used the value is set to null. | |
* #!x&y=3 -> { x:null, y:3 } | |
* @param url URL to parse or null if window.location is used | |
* @return Object of key -> value mappings. | |
* @source https://gist.github.com/zaus/5201739 | |
*/ | |
function hashbang(url, i, hash) { | |
url = url || window.location.href; | |
var vars = {}, hashes = url.slice(url.indexOf('#!') + 2).split('&'); | |
for(i = hashes.length; i--;) { | |
hash = hashes[i].split('='); | |
vars[hash[0]] = hash.length > 1 ? hash[1] : null; | |
} | |
return vars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a bit better: