Last active
August 19, 2021 18:44
-
-
Save foriacus/7745513 to your computer and use it in GitHub Desktop.
querystring
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
| var trim = require('trim'); | |
| exports.parse = function(str){ | |
| if ('string' != typeof str) return {}; | |
| str = trim(str); | |
| if ('' == str) return {}; | |
| var obj = {}; | |
| var pairs = str.split('&'); | |
| for (var i = 0; i < pairs.length; i++) { | |
| var parts = pairs[i].split('='); | |
| obj[parts[0]] = null == parts[1] | |
| ? '' | |
| : decodeURIComponent(parts[1]); | |
| } | |
| return obj; | |
| }; | |
| exports.stringify = function(obj){ | |
| if (!obj) return ''; | |
| var pairs = []; | |
| for (var key in obj) { | |
| pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])); | |
| } | |
| return pairs.join('&'); | |
| }; | |
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
| var querystring = require('querystring'); | |
| querystring.parse(window.location.search.slice(1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment