unserialize.js 563 B

123456789101112131415161718192021222324
  1. var staticDecodeURIComponent = require('../static/staticDecodeURIComponent')
  2. var arrayEach = require('../array/arrayEach')
  3. var isString = require('../base/isString')
  4. /**
  5. * 反序列化查询参数
  6. *
  7. * @param {String} query 字符串
  8. */
  9. function unserialize (str) {
  10. var items
  11. var result = {}
  12. if (str && isString(str)) {
  13. arrayEach(str.split('&'), function (param) {
  14. items = param.split('=')
  15. result[staticDecodeURIComponent(items[0])] = staticDecodeURIComponent(items[1] || '')
  16. })
  17. }
  18. return result
  19. }
  20. module.exports = unserialize