-
-
Save edwilliams/395f58efcf5554c46933e35b5be85a45 to your computer and use it in GitHub Desktop.
Parse query string. use Underscore.js.
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 query string. | |
| * ?a=b&c=d to {a: b, c: d} | |
| * @param {String} (option) queryString | |
| * @return {Object} query params | |
| */ | |
| _.getQueryParams = function(queryString) { | |
| if (!queryString) { return false; } | |
| return _.chain(queryString.split('&')) | |
| .map(function(params) { | |
| var p = params.split('='); | |
| return [p[0], decodeURIComponent(p[1])]; | |
| }) | |
| .object() | |
| .value(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment