unserialize.js 539 B

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