Created
January 6, 2016 13:10
-
-
Save pzzrudlf/3064fbf2355cd89a3519 to your computer and use it in GitHub Desktop.
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
| function parseQuery(query){ | |
| var args = {}; | |
| var items = query.split("&"); | |
| var item = null, name = null, value = null; | |
| for(var i=0; i < items.length; i++){ | |
| item = items[i].split("="); | |
| if(item[0]){ | |
| name = item[0]; | |
| value = item[1] ? item[1] : ""; | |
| args[name] = value; | |
| } | |
| } | |
| return args; | |
| } | |
| function parseQuery(str){ | |
| return str.split('&').reduce((memo, x) => { | |
| let qa = x.split('='); | |
| if(!qa[0]) return memo; | |
| return Object.assign(memo, { | |
| [qa[0]]: qa[1]?qa[1]:"" | |
| }) | |
| }, {}) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment