blob: f8b486f96bce5004a252ea138d0b9d739c9608d1 [file] [log] [blame]
Yang Guo4fd355c2019-09-19 08:59:031/**
2 * Compiles a querystring
3 * Returns string representation of the object
4 *
5 * @param {Object}
6 * @api private
7 */
8
9exports.encode = function (obj) {
10 var str = '';
11
12 for (var i in obj) {
13 if (obj.hasOwnProperty(i)) {
14 if (str.length) str += '&';
15 str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
16 }
17 }
18
19 return str;
20};
21
22/**
23 * Parses a simple querystring into an object
24 *
25 * @param {String} qs
26 * @api private
27 */
28
29exports.decode = function(qs){
30 var qry = {};
31 var pairs = qs.split('&');
32 for (var i = 0, l = pairs.length; i < l; i++) {
33 var pair = pairs[i].split('=');
34 qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
35 }
36 return qry;
37};