You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
745 B

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